Pascal Dialects Compared
37.1 Feature matrix
Turbo Pascal 7 Classes, exceptions Result variable Default string packed array of char
ShortString (AnsiString with {$H+}) Integer size @ needed for procedural values Inline variables (var X:= 1) case on strings Global operator overloading no (class operators) Macros ({$macro on})
Conditional expression if ... then ... else
37.2 Other Pascal implementations
GNU Pascal (GPC) GCC front end supporting ISO 7185/10206; no longer maintained educational Pascal for.NET with modern extensions; popular in Russian-speaking schools Oxygene (RemObjects Elements)
Object Pascal for .NET, Java/Android, Cocoa, and native targets
Object Pascal to JavaScript transpiler from the FPC team (used by TMS WEB Core) Smart Mobile Studio
Object Pascal to JavaScript (commercial) Turbo51, mikroPascal Pascal for microcontrollers Delphi Prism former name of Oxygene in RAD Studio
37.3 Writing code for both Delphi and FPC
Use {$mode delphi} in FPC for Delphi code; check string size assumptions (SizeOf(Char) is 1 in FPC delphi mode, 2 in Delphi) or use {$mode delphiunicode}.
Replace Windows-only units (Windows, Messages, ShellAPI) with cross-platform equivalents or {$IFDEF MSWINDOWS}.
VCL → LCL: most standard controls have the same names and properties; Lazarus has a Delphi conversion tool (*Tools → Delphi Conversion*).
.dfm ↔ .lfm: Lazarus converts form files; remove unsupported properties.
Avoid Delphi-only syntax (inline variables, anonymous methods for FPC 3.2) in shared code.
unit Portable;
{$IFDEF FPC}
{$mode delphi}{$H+}
{$ENDIF}
interface
uses
{$IFDEF FPC}
SysUtils, Classes, Generics.Collections;
{$ELSE}
System.SysUtils, System.Classes, System.Generics.Collections;
{$ENDIF}🧪 Part III Exercises
Design a class hierarchy for an employee payroll system (TEmployee, TSalaried, THourly, TCommissioned) with an abstract Pay method; process a polymorphic TObjectList<TEmployee>.
Implement a TTemperature class with Celsius/Fahrenheit/Kelvin properties, validation in setters, and an OnChange event fired whenever the value changes.
Build a plugin registry using metaclasses and virtual constructors: register classes by name in a TDictionary<string, TPluginClass> and create them from user input.
Define IShape and IPrintable interfaces, implement them in several classes, and demonstrate automatic destruction via reference counting; then create (and fix) a reference cycle.
Write a generic TObservableList<T> that raises events on add/remove, using TList<T> internally, and specialize it for Integer, string, and a record type.
Implement a TMoney advanced record with Currency storage, +, -, * (by integer), comparison operators, Implicit from Currency, and a ToString that formats with a currency code.
Write a record helper for TDateTime (or a class helper for TStrings) with five useful methods; explain why you could not add a field.
Implement a custom collection (e.g. a ring buffer) with a for-in enumerator and test it with several element types via generics.
Using published properties and TypInfo (or Delphi extended RTTI), write a function that saves any object's properties to an INI section and loads them back.
Write a multithreaded prime counter that splits a range among N threads, combines results safely, and compares the timing for 1, 2, 4, and 8 threads; check the program for leaks with heaptrc or ReportMemoryLeaksOnShutdown.