Data Types

Use Low(T) / High(T) and SizeOf(T) to query ranges and sizes:

5.1 Type classification

Simple types
  ├─ Ordinal: Integer family, Char family, Boolean family, enumerated, subrange
  └─ Real: Single, Double, Extended, Currency, Comp, Real
String types: ShortString, AnsiString, UnicodeString, WideString, PChar/PAnsiChar/PWideChar
Structured types: array, record, set, file, class, interface, object
Pointer types: Pointer, ^T, procedural types, method pointers
Variant types: Variant, OleVariant

5.2 Integer types

ShortInt / Int8 Byte / UInt8 SmallInt / Int16 Word / UInt16 LongInt / Int32

Delphi: 8 bytes on 64-bit iOS/macOS/Linux/Android LongWord / Cardinal / UInt32 / DWord DWord is FPC/Windows −9.2e18.. 9.2e18 UInt64 / QWord QWord is FPC same as LongInt 2 bytes in FPC fpc/tp modes NativeInt / NativeUInt FPC also PtrInt, PtrUInt, SizeInt

Use Low(T) / High(T) and SizeOf(T) to query ranges and sizes:

Writeln(Low(Integer), ' .. ', High(Integer));
Writeln(SizeOf(Int64));   // 8

5.3 Real (floating-point) types

IEEE 754 single IEEE 754 double — the usual choice alias of Double in Delphi and FPC (6-byte Real48 is legacy)

80-bit on 32-bit x86; equals Double on Win64 and most non-x86 targets 4 fixed decimals scaled Int64; ideal for money integer stored in FPU format

5.4 Boolean types

False < True, Ord(True) = 1 ByteBool, WordBool, LongBool any non-zero value is true; for C/Windows API interop

5.5 Character types

UTF-16 code unit WideChar in Delphi 2009+ and FPC delphiunicode/unicodestrings; AnsiChar in FPC objfpc

var C: Char;
begin
  C := 'A';
  Writeln(Ord(C));          // 65
  Writeln(Chr(66));         // B
  Writeln(Succ(C));         // B
  Writeln(UpCase('q'));     // Q
end.

5.6 String types

ShortString / String[N] length byte + up to 255 bytes, on the stack

Turbo Pascal legacy; S[0] holds the length heap, reference-counted, copy-on-write carries a code page in Delphi 2009+/FPC 3.0+ Lazarus LCL uses UTF-8 strings heap, ref-counted, UTF-16 Delphi's default string since 2009 COM BSTR, not ref-counted for COM/OLE interop PChar, PAnsiChar, PWideChar pointer to null-terminated chars for C/OS API calls What does plain string mean?

FPC {$mode objfpc}{$H+} or {$mode delphi} AnsiString (UTF-8 in Lazarus programs)

FPC {$H-} (default in fpc/tp modes) FPC {$mode delphiunicode} or {$modeswitch unicodestrings}

Strings are 1-based: S[1] is the first character (Delphi mobile compilers once used 0-based strings; since 10.4 all platforms default to 1-based again).

5.7 Enumerated and subrange types (preview)

Covered in depth in Chapter 16.

type
  TColor = (Red, Green, Blue);       // enumerated: Ord(Red) = 0
  TDigit = 0..9;                     // subrange of Integer
  TUpper = 'A'..'Z';                 // subrange of Char

5.8 Variant

Variant (unit Variants) can hold integers, reals, strings, dates, booleans, arrays, Null, and COM objects, with runtime type checks. Useful for databases and COM; avoid in normal code because it is slower and loses compile-time checking.

5.9 Type declarations and type identity

type
  TAge = Integer;            // alias: fully compatible with Integer
  TMeters = type Double;     // distinct type: separate RTTI, distinct for overloading