The System unit
Every program uses System without naming it. It holds the standard
procedures and functions, which the compiler knows and which are not ordinary
routines (they may take any type, change their arguments or be evaluated at compile
time). Standard Pascal (ISO 7185) has the first group; Turbo Pascal, Delphi and Free Pascal
have the rest.
| Group | Routines |
|---|---|
| Arithmetic | Abs Sqr Sqrt Sin Cos ArcTan Ln Exp Pi Frac Int Trunc Round Odd Random Randomize Inc Dec Hi Lo Swap |
| Ordinals | Ord Chr Succ Pred Low High Include Exclude |
| Strings and characters | Length SetLength Copy Pos Delete Insert Concat UpCase Str Val SetString FillChar StringOfChar (also Trim UpperCase LowerCase IntToStr StrToInt Format in SysUtils) |
| Memory | New Dispose GetMem FreeMem ReallocMem Initialize Finalize Move FillChar FillWord SizeOf TypeOf Addr Ptr Mark Release |
| Files and input/output | Assign Reset Rewrite Append Close Read ReadLn Write WriteLn Eof Eoln SeekEof SeekEoln Seek FilePos FileSize Truncate Flush Erase Rename BlockRead BlockWrite IOResult ChDir MkDir RmDir GetDir; ISO 7185’s Get Put Page Pack Unpack |
| Program control | Halt Exit Break Continue RunError ParamCount ParamStr Assigned Assert |
| Compile-time | SizeOf High Low Ord Chr Length Defined Declared TypeInfo Default |
| Variants, interfaces, classes | VarType VarIsNull Supports TObject IUnknown TInterfacedObject |
| Exceptions | Abort ExceptObject ExceptAddr RaiseList ErrorAddr ExitCode |
The System unit also declares the standard types (the
Types page), the constants MaxInt,
MaxLongInt, the variables Input, Output,
ErrOutput, ExitCode, ErrorAddr and RandSeed, and the
class TObject with IInterface, IUnknown and
TInterfacedObject.
Main units of Delphi and Free Pascal
| Unit | Holds |
|---|---|
System, SysInit | the language’s intrinsics and base classes |
SysUtils (System.SysUtils) | string, date and file helpers, IntToStr, StrToInt, Format, FormatFloat, Trim, UpperCase, FileExists, Now, Exception, FreeAndNil, IncludeTrailingPathDelimiter |
Classes (System.Classes) | TList, TStringList, TStrings, TStream, TFileStream, TMemoryStream, TComponent, TPersistent, TThread, TReader, TWriter |
Types, TypInfo, Rtti | common types (TPoint, TRect), run-time type information, reflection |
Math | trigonometry, rounding (Ceil, Floor, RoundTo), Min, Max, Power, statistics |
StrUtils, Character, AnsiStrings, Strings | more string routines, PosEx, ReplaceStr, Unicode character classes, C-style PChar routines |
DateUtils | date and time arithmetic: IncDay, DaysBetween, StartOfTheDay |
Variants, VarUtils | the Variant machinery |
Generics.Collections, Generics.Defaults | generic containers (see Generics) |
IOUtils, Masks, Contnrs | TPath, TFile, TDirectory; masks; the older object lists |
Windows (Winapi.Windows), Messages, ShellAPI, ActiveX, ComObj | the Windows API, messages, COM |
BaseUnix, Unix, Linux, Posix.* | Unix system calls (Free Pascal, Delphi for Linux and macOS) |
Vcl.*, FMX.*, LCL (Forms, Controls, StdCtrls, Graphics, Dialogs) | the visual component libraries of Delphi (VCL, FireMonkey) and Lazarus (LCL) |
DB, SQLDB, FireDAC.* | database access |
Sockets, IdTCPClient (Indy), fphttpclient, Net.* | networking |
DOM, XMLRead, fpjson, jsonparser, System.JSON, Xml.* | XML and JSON |
Free Pascal calls its runtime library the RTL and its class library the FCL; the units for graphics, forms and controls are Lazarus’s LCL. Delphi’s are the RTL and the VCL or FireMonkey.
Turbo Pascal units
| Unit | Holds |
|---|---|
System | the standard routines, always present |
Crt | the text screen and keyboard: ClrScr, GotoXY, TextColor, TextBackground, ReadKey, KeyPressed, Delay, Sound, Window |
Dos | DOS calls: GetDate, GetTime, FindFirst, FindNext, Intr, MsDos, Exec, GetEnv, DiskFree |
Graph | the Borland Graphics Interface: InitGraph, Line, Circle, PutPixel, SetColor, OutTextXY |
Printer, Overlay, Strings, Objects, WinCrt, WinDos, WinProcs, WinTypes, OWindows | the list printer, overlays, PChar strings, the Turbo Vision object library, and the Windows versions of these for Borland Pascal 7 and Turbo Pascal for Windows |
App, Views, Dialogs, Menus, Drivers, MsgBox | Turbo Vision (text-mode windows and menus), also ported to Free Pascal |
Free Pascal has its own Crt, Dos, Graph and
Objects units for compatibility.
Input and output
var
F: TextFile;
Line: string;
begin
Assign(F, 'data.txt');
Reset(F);
while not Eof(F) do
begin
ReadLn(F, Line);
WriteLn(Length(Line):6, ' ', Line); { :6 is a field width }
end;
Close(F);
WriteLn(Pi:10:4); { width 10, 4 decimals: ' 3.1416' }
end;
Write and WriteLn take any number of arguments of simple types and
strings, each optionally followed by :width and, for reals, :decimals.
Read and ReadLn read the same kinds from the input. A first argument
that is a file variable names the file; with none, Output and
Input (the console) are used. These are not ordinary routines, which is why
they take the : forms.
The names the viewer colours
The file viewer on this site colours these names by themselves (without help from the context). A name that matches is coloured in the stated way unless it follows a dot (a member) or, for a type, is followed by a colon (a variable or parameter of that name).
| Colour | Names |
|---|---|
| type | ansichar ansistring boolean byte bytebool cardinal char comp currency double dword extended hresult int16 int32 int64 int8 integer iinterface iunknown idispatch longbool longint longword nativeint nativeuint olevariant pansichar pchar pointer pwidechar qword qwordbool rawbytestring real real48 shortint shortstring single size_t sizeint sizeuint smallint string text textfile tclass tdatetime tinterfacedobject tobject tpersistent uint16 uint32 uint64 uint8 ucs4char unicodechar unicodestring utf8string variant widechar widestring word wordbool exception tcomponent tlist tstringlist tstrings tstream tthread tobjectlist |
| literal | true false nil maxint maxlongint |
| function (without a parenthesis) | break continue eof eoln exit halt ioresult paramcount pi random randomize readln seekeof seekeoln writeln |
| variable | result |
| function (with a parenthesis) | every other name directly followed by (, which covers the remaining standard routines above |