44 < div class ="container ">
55 < div class ="hero-content ">
66 < div class ="hero-text ">
7- < h1 > Pascal</ h1 >
7+ < h1 > Object Pascal</ h1 >
88 < p class ="hero-subtitle "> Build readable, fast and reliable software.</ p >
99 < div class ="hero-actions ">
1010 < a href ="{{ "/learn/" | relURL }}" class="hero-cta primary"> Get Started</ a >
@@ -13,28 +13,272 @@ <h1>Pascal</h1>
1313 < p class ="version-info "> Latest: Free Pascal 3.2.2 • Lazarus 4.2</ p >
1414 </ div >
1515 < div class ="hero-code ">
16- {{ $heroCode := `program webserver;
17- {$mode objfpc}{$H+}
18-
16+ < div class ="code-selector ">
17+ < button class ="code-tab active " data-example ="webserver "> Web Server</ button >
18+ < button class ="code-tab " data-example ="sorting "> Data Processing</ button >
19+ < button class ="code-tab " data-example ="json "> JSON API</ button >
20+ < button class ="code-tab " data-example ="filestream "> File Processing</ button >
21+ < button class ="code-tab " data-example ="sqlite "> SQLite DB</ button >
22+ < button class ="code-tab " data-example ="csv "> CSV Parser</ button >
23+ < button class ="code-tab " data-example ="concurrent "> Concurrency</ button >
24+ </ div >
25+
26+ < div class ="code-examples ">
27+ < div class ="code-example active " id ="example-webserver ">
28+ {{ $webserverCode := `program webserver;
29+
30+ {$mode objfpc}{$H+}{$J-}
31+
1932uses
20- {$ifdef UNIX}
21- cthreads, cmem,
22- {$endif}
23- fphttpapp, httpdefs, httproute;
24-
33+ Classes, fphttpapp, httpdefs, httproute;
34+
2535procedure route1(aReq: TRequest; aResp: TResponse);
2636begin
27- aResp.Content:=' < html > < body > < h1 > Hello Pascal!</ h1 > </ body > </ html > ';
37+ aResp.Content := ' < h1 > Hello Pascal!</ h1 > ';
2838end;
29-
39+
3040begin
3141 HTTPRouter.RegisterRoute('/', @route1);
3242 Application.Port := 1999;
3343 Application.Threaded := true;
3444 Application.Initialize;
45+
46+ WriteLn('Your site is ready at: http://localhost:1999');
47+ WriteLn('Hit Ctrl + C to quit');
48+
3549 Application.Run;
3650end.` }}
37- {{ highlight $heroCode "objectpascal" "linenos=false" }}
51+ {{ highlight $webserverCode "objectpascal" "linenos=false" }}
52+ </ div >
53+
54+ < div class ="code-example " id ="example-sorting ">
55+ {{ $sortingCode := `program datasort;
56+
57+ {$mode objfpc}{$H+}{$J-}
58+
59+ uses
60+ SysUtils, Classes, Generics.Collections;
61+
62+ type
63+ TListInt = specialize TList< integer > ;
64+
65+ var
66+ Numbers: TListInt;
67+ Num: integer;
68+
69+ begin
70+ Numbers := TListInt.Create();
71+ try
72+ Numbers.AddRange([1, 45, 78, 99, 32, 47]);
73+ Numbers.Sort;
74+
75+ for Num in Numbers do
76+ WriteLn(Num);
77+ finally
78+ Numbers.Free;
79+ end;
80+ end.` }}
81+ {{ highlight $sortingCode "objectpascal" "linenos=false" }}
82+ </ div >
83+
84+ < div class ="code-example " id ="example-json ">
85+ {{ $jsonCode := `program jsonapi;
86+
87+ {$mode objfpc}{$H+}{$J-}
88+
89+ uses
90+ fpjson, jsonparser;
91+
92+ var
93+ JSON: TJSONObject;
94+ begin
95+ JSON := GetJSON('{"name":"Alice","age":30}') as TJSONObject;
96+ try
97+ WriteLn(JSON.Get('name', ''), ' is ', JSON.Get('age', 0), ' years old');
98+ finally
99+ JSON.Free;
100+ end;
101+ end.` }}
102+ {{ highlight $jsonCode "objectpascal" "linenos=false" }}
103+ </ div >
104+
105+ < div class ="code-example " id ="example-filestream ">
106+ {{ $filestreamCode := `program fileprocess;
107+
108+ {$mode objfpc}{$H+}{$J-}
109+
110+ uses
111+ Classes, SysUtils, streamex;
112+
113+ var
114+ FileStream: TFileStream;
115+ Reader: TStreamReader;
116+ Line: string;
117+ LineNum: integer;
118+
119+ begin
120+ FileStream := TFileStream.Create('data.txt', fmOpenRead);
121+ try
122+ Reader := TStreamReader.Create(FileStream);
123+ try
124+ LineNum := 1;
125+ while not Reader.EOF do
126+ begin
127+ Line := Reader.ReadLine;
128+ WriteLn('Line ', LineNum, ': ', Line);
129+ Inc(LineNum);
130+ end;
131+ finally
132+ Reader.Free;
133+ end;
134+ finally
135+ FileStream.Free;
136+ end;
137+ end.` }}
138+ {{ highlight $filestreamCode "objectpascal" "linenos=false" }}
139+ </ div >
140+
141+ < div class ="code-example " id ="example-sqlite ">
142+ {{ $sqliteCode := `program sqlite;
143+
144+ {$mode objfpc}{$H+}
145+
146+ uses
147+ SysUtils, sqldb, sqlite3conn;
148+
149+ var
150+ Conn: TSQLite3Connection;
151+ Query: TSQLQuery;
152+ Trans: TSQLTransaction;
153+
154+ begin
155+ Conn := TSQLite3Connection.Create(nil);
156+ Trans := TSQLTransaction.Create(nil);
157+ Query := TSQLQuery.Create(nil);
158+ try
159+ Conn.DatabaseName := 'users.db';
160+ Conn.Transaction := Trans;
161+ Trans.Database := Conn;
162+ Query.Database := Conn;
163+ Query.Transaction := Trans;
164+
165+ Conn.Open;
166+
167+ // Simple query
168+ Query.SQL.Text := 'SELECT name, age FROM users WHERE age > 25';
169+ Query.Open;
170+
171+ while not Query.EOF do
172+ begin
173+ WriteLn(Query.FieldByName('name').AsString, ' is ',
174+ Query.FieldByName('age').AsInteger, ' years old');
175+ Query.Next;
176+ end;
177+ finally
178+ Query.Free;
179+ Trans.Free;
180+ Conn.Free;
181+ end;
182+ end.` }}
183+ {{ highlight $sqliteCode "objectpascal" "linenos=false" }}
184+ </ div >
185+
186+ < div class ="code-example " id ="example-csv ">
187+ {{ $csvCode := `program csvparser;
188+
189+ {$mode objfpc}{$H+}{$J-}
190+
191+ uses
192+ SysUtils, csvdocument;
193+
194+ var
195+ CSV: TCSVDocument;
196+ Row, Col: Integer;
197+
198+ begin
199+ CSV := TCSVDocument.Create;
200+ try
201+ CSV.LoadFromFile('data.csv');
202+
203+ WriteLn('CSV has ', CSV.RowCount, ' rows and ', CSV.ColCount[0], ' columns');
204+ WriteLn;
205+
206+ for Row := 0 to CSV.RowCount - 1 do
207+ begin
208+ Write('Row ', Row + 1, ': ');
209+ for Col := 0 to CSV.ColCount[0] - 1 do
210+ begin
211+ Write(CSV.Cells[Col, Row]);
212+ if Col < CSV .ColCount[0] - 1 then Write( ' | ');
213+ end;
214+ WriteLn;
215+ end;
216+ finally
217+ CSV.Free;
218+ end;
219+ end.` }}
220+ {{ highlight $csvCode "objectpascal" "linenos=false " }}
221+ </ div >
222+
223+ < div class ="code-example " id ="example-concurrent ">
224+ {{ $concurrentCode := `program concurrent;
225+
226+ {$mode objfpc}{$H+}{$J-}
227+
228+ uses
229+ {$IFDEF UNIX}
230+ cthreads, cmem
231+ {$ENDIF}
232+ SysUtils, Classes, SyncObjs;
233+
234+ type
235+ TWorkerThread = class(TThread)
236+ private
237+ FTaskID: Integer;
238+ protected
239+ procedure Execute; override;
240+ public
241+ constructor Create(TaskID: Integer);
242+ end;
243+
244+ constructor TWorkerThread.Create(TaskID: Integer);
245+ begin
246+ FTaskID := TaskID;
247+ inherited Create(False);
248+ end;
249+
250+ procedure TWorkerThread.Execute;
251+ begin
252+ WriteLn('Task ', FTaskID, ' starting...');
253+ Sleep(1000 + Random(2000)); // Simulate work
254+ WriteLn('Task ', FTaskID, ' completed!');
255+ end;
256+
257+ var
258+ Threads: array[1..4] of TWorkerThread;
259+ i: Integer;
260+
261+ begin
262+ Randomize;
263+
264+ // Start concurrent tasks
265+ for i := 1 to 4 do
266+ Threads[i] := TWorkerThread.Create(i);
267+
268+ // Wait for completion
269+ for i := 1 to 4 do
270+ begin
271+ Threads[i].WaitFor;
272+ Threads[i].Free;
273+ end;
274+
275+ WriteLn('All tasks completed!');
276+ end.
277+
278+ ` }}
279+ {{ highlight $concurrentCode "objectpascal" "linenos=false" }}
280+ </ div >
281+ </ div >
38282 </ div >
39283 </ div >
40284 </ div >
0 commit comments