Quick start manual
5-6
Delphi Language Guide
Simple types
For more information about Unicode characters, see “About extended character sets”
on page 5-13 and “Working with null-terminated strings” on page 5-14.
Boolean types
The four predefined Boolean types are Boolean, ByteBool, WordBool, and LongBool.
Boolean is the preferred type. The others exist to provide compatibility with other
languages and operating system libraries.
A Boolean variable occupies one byte of memory, a ByteBool variable also occupies
one byte, a WordBool variable occupies two bytes (one word), and a LongBool variable
occupies four bytes (two words).
Boolean values are denoted by the predefined constants True and False. The
following relationships hold.
A value of type ByteBool, LongBool, or WordBool is considered True when its ordinality
is nonzero. If such a value appears in a context where a Boolean is expected, the
compiler automatically converts any value of nonzero ordinality to True.
The previous remarks refer to the ordinality of Boolean values, not to the values
themselves. In Delphi, Boolean expressions cannot be equated with integers or reals.
Hence, if X is an integer variable, the statement
if X then ...;
generates a compilation error. Casting the variable to a Boolean type is unreliable,
but each of the following alternatives will work.
if X <> 0 then ...; { use longer expression that returns Boolean value }
var OK: Boolean { use Boolean variable }
ƒ
if X <> 0 then OK := True;
if OK then ...;
Enumerated types
An enumerated type defines an ordered set of values by simply listing identifiers that
denote these values. The values have no inherent meaning. To declare an
enumerated type, use the syntax
type typeName = (val
1
, ..., val
n
)
where typeName and each val are valid identifiers. For example, the declaration
type Suit = (Club, Diamond, Heart, Spade);
Boolean ByteBool, WordBool, LongBool
False < True False <> True
Ord(False) = 0 Ord(False) = 0
Ord(True) = 1 Ord(True) <> 0
Succ(False) = True Succ(False) = True
Pred(True) = False Pred(False) = True