Four Boolean types are defined in Delphi: Boolean, ByteBool, WordBool, and LongBool. The last three Boolean types are introduced for compatibility with other languages. In general, the Boolean type is recommended.
The amount of memory occupies these four types of boolean values is as follows:
Boolean 1 Byte
ByteBool 1 Byte
WordBool 2 Bytes (1 Word)
LongBool 4 Bytes (2 Words)
For ByteBool, the values of the three types of True constants, WordBool and LongBool, are non-zero, and False is zero, which can be verified by the Ord function;
For Boolean type, the value of True constant is 1 and False is zero. In the context of expecting Boolean values, the compiler converts non-zero values of ByteBool, WordBool and LongBool to True.
However, boolean expressions and Integer/Real are incompatible in Delphi. The following table compares the similarities and differences between Boolean and ByteBool/WordBool/LongBool:
Boolean
False < True
Ord(False) = 0
Ord(True) = 1
Succ(False) = True
PRed(True) = False
BoolToStr(True) = -1 //This function is very abnormal
BoolToStr(False) = 0
ByteBool, WordBool, LongBool
False <> True
Ord(False) = 0
Ord(True) <> 0
Succ(False) = True
Pred(False) = True
The BoolToStr function is the most inexplicable. It clearly says that the value of True is 1, but it tells us that True is -1. The prototype of the function is:
function BoolToStr(B: Boolean; UseBoolStrs: Boolean = False): string;
The following table is the conversion rules for functions:
BUseBoolStrsValue of returned string
TrueFalse'-1'
True True The first value of TrueBoolStrs array (default, 'TRUE')
False False '0'
False True The first value of the FalseBoolStrs array (default, 'FALSE')