Pascal

Build readable, fast and reliable software.

With Free Pascal Compiler (FPC), Delphi, PascalABC.Net, and more.

program webserver;

{$mode objfpc}{$H+}{$J-}

uses
  Classes, fphttpapp, httpdefs, httproute;

procedure route1(aReq: TRequest; aResp: TResponse);
begin
  aResp.Content := '<h1>Hello Pascal!</h1>';
end;

begin
  HTTPRouter.RegisterRoute('/', @route1);
  Application.Port := 1999;
  Application.Threaded := true;
  Application.Initialize;

  WriteLn('Your site is ready at: http://localhost:1999');
  WriteLn('Hit Ctrl + C to quit');

  Application.Run;
end.
program datasort;

{$mode objfpc}{$H+}{$J-}

uses
  SysUtils, Classes, Generics.Collections;
 
type
  TListInt = specialize TList<integer>;
 
var
  Numbers: TListInt;
  Num: integer;
 
begin
  Numbers := TListInt.Create();
  try
    Numbers.AddRange([1, 45, 78, 99, 32, 47]);
    Numbers.Sort;
 
    for Num in Numbers do
      WriteLn(Num);
  finally
    Numbers.Free;
  end;
end.
program jsonapi;

{$mode objfpc}{$H+}{$J-}

uses
  fpjson, jsonparser;

var
  JSON: TJSONObject;
begin
  JSON := GetJSON('{"name":"Alice","age":30}') as TJSONObject;
  try
    WriteLn(JSON.Get('name', ''), ' is ', JSON.Get('age', 0), ' years old');
  finally
    JSON.Free;
  end;
end.
program fileprocess;

{$mode objfpc}{$H+}{$J-}
 
 uses
   Classes, SysUtils, streamex;
 
 var
   FileStream: TFileStream;
   Reader: TStreamReader;
   Line: string;
   LineNum: integer;
 
 begin
   FileStream := TFileStream.Create('data.txt', fmOpenRead);
   try
     Reader := TStreamReader.Create(FileStream);
     try
       LineNum := 1;
       while not Reader.EOF do
       begin
         Line := Reader.ReadLine;
         WriteLn('Line ', LineNum, ': ', Line);
         Inc(LineNum);
       end;
     finally
       Reader.Free;
     end;
   finally
     FileStream.Free;
   end;
 end.
program sqlite;

{$mode objfpc}{$H+}{$J-}

uses
  SysUtils, sqldb, sqlite3conn;

var
  Conn: TSQLite3Connection;
  Query: TSQLQuery;
  Trans: TSQLTransaction;

begin
  Conn := TSQLite3Connection.Create(nil);
  Trans := TSQLTransaction.Create(nil);
  Query := TSQLQuery.Create(nil);
  try
    Conn.DatabaseName := 'users.db';
    Conn.Transaction := Trans;
    Trans.Database := Conn;
    Query.Database := Conn;
    Query.Transaction := Trans;
    
    Conn.Open;

    // Simple query
    Query.SQL.Text := 'SELECT name, age FROM users WHERE age > 25';
    Query.Open;

    while not Query.EOF do
    begin
      WriteLn(Query.FieldByName('name').AsString, ' is ',
              Query.FieldByName('age').AsInteger, ' years old');
      Query.Next;
    end;
  finally
    Query.Free;
    Trans.Free;
    Conn.Free;
  end;
end.
program csvparser;

{$mode objfpc}{$H+}{$J-}

uses
  SysUtils, csvdocument;

var
  CSV: TCSVDocument;
  Row, Col: Integer;

begin
  CSV := TCSVDocument.Create;
  try
    CSV.LoadFromFile('data.csv');

    WriteLn('CSV has ', CSV.RowCount, ' rows and ', CSV.ColCount[0], ' columns');
    WriteLn;

    for Row := 0 to CSV.RowCount - 1 do
    begin
      Write('Row ', Row + 1, ': ');
      for Col := 0 to CSV.ColCount[0] - 1 do
      begin
        Write(CSV.Cells[Col, Row]);
        if Col < CSV.ColCount[0] - 1 then Write(' | ');
      end;
      WriteLn;
    end;
  finally
    CSV.Free;
  end;
end.
program concurrent;

{$mode objfpc}{$H+}{$J-}

uses
  {$IFDEF UNIX}
  cthreads, cmem
  {$ENDIF}
  SysUtils, Classes, SyncObjs;

type
  TWorkerThread = class(TThread)
  private
    FTaskID: Integer;
  protected
    procedure Execute; override;
  public
    constructor Create(TaskID: Integer);
  end;

constructor TWorkerThread.Create(TaskID: Integer);
begin
  FTaskID := TaskID;
  inherited Create(False);
end;

procedure TWorkerThread.Execute;
begin
  WriteLn('Task ', FTaskID, ' starting...');
  Sleep(1000 + Random(2000)); // Simulate work
  WriteLn('Task ', FTaskID, ' completed!');
end;

var
  Threads: array[1..4] of TWorkerThread;
  i: Integer;

begin
  Randomize;

  // Start concurrent tasks
  for i := 1 to 4 do
    Threads[i] := TWorkerThread.Create(i);

  // Wait for completion
  for i := 1 to 4 do
  begin
    Threads[i].WaitFor;
    Threads[i].Free;
  end;

  WriteLn('All tasks completed!');
end.

Why Pascal?

Readability

Pascal's clean, English-like syntax makes code self-documenting. Strong structure and clear semantics eliminate guesswork, making maintenance a breeze for teams of any size.

Reliability

Pascal's strong type system and compile-time checks catch errors before they reach production. Memory safety and structured programming prevent entire classes of bugs.

Productivity

Pascal has excellent tooling, comprehensive libraries, and cross-platform support. Rapid development cycles with integrated debugging and visual designers boost developer efficiency.

Quick Start

1. Install

Download and install Free Pascal or Lazarus IDE to start coding immediately.

Quick Setup →

2. Learn

Learn the essential concepts of Pascal and build your first program.

Start Learning →

3. Build

Explore Pascal resources; docs, examples, tutorials and more.

View Resources →

Join the Community

Connect with Pascal developers worldwide, share knowledge, and contribute to the growing Pascal ecosystem.

Join Community