Quick start manual
Data types, variables, and constants
5-5
Simple types
When you increment the last value or decrement the first value of an integer type, the
result wraps around the beginning or end of the range. For example, the Shortint type
has the range –128..127; hence, after execution of the code
var I: Shortint;
ƒ
I := High(Shortint);
I := I + 1;
the value of I is –128. If compiler range-checking is enabled, however, this code
generates a runtime error.
Character types
The fundamental character types are AnsiChar and WideChar. AnsiChar values are
byte-sized (8-bit) characters ordered according to the locale character set which is
possibly multibyte. AnsiChar was originally modeled after the ANSI character set
(thus its name) but has now been broadened to refer to the current locale character
set.
WideChar characters use more than one byte to represent every character. In the
current implementations, WideChar is word-sized (16-bit) characters ordered
according to the Unicode character set (note that it could be longer in future
implementations). The first 256 Unicode characters correspond to the ANSI
characters.
Note
On Linux, wchar_t widechar is 32 bits per character. The 16-bit Unicode standard
that Delphi WideChars support is a subset of the 32-bit UCS standard supported by
Linux and the GNU libraries. Delphi WideChar data must be widened to 32 bits per
character before it can be passed to an OS function as wchar_t.
The generic character type is Char, which is equivalent to AnsiChar. Because the
implementation of Char is subject to change, it’s a good idea to use the standard
function SizeOf rather than a hard-coded constant when writing programs that may
need to handle characters of different sizes.
A string constant of length 1, such as 'A', can denote a character value. The
predefined function Chr returns the character value for any integer in the range of
AnsiChar or WideChar; for example, Chr(65) returns the letter A.
Character values, like integers, wrap around when decremented or incremented past
the beginning or end of their range (unless range-checking is enabled). For example,
after execution of the code
var
Letter: Char;
I: Integer;
begin
Letter := High(Letter);
for I := 1 to 66 do
Inc(Letter);
end;
Letter has the value A (ASCII 65).