Quick start manual
Data types, variables, and constants
5-35
Variant types
Out-of-range assignments often result in the target variable getting the highest value
in its range. Invalid variant operations, assignments or casts raise an EVariantError
exception or an exception class decending from EVariantError.
Special conversion rules apply to the TDateTime real type declared in the System unit.
When a TDateTime is converted to any other type, it treated as a normal Double. When
an integer, real, or Boolean is converted to a TDateTime, it is first converted to a
Double, then read as a date-time value. When a string is converted to a TDateTime, it is
interpreted as a date-time value using the regional settings. When an Unassigned
value is converted to TDateTime, it is treated like the real or integer value 0.
Converting a Null value to TDateTime raises an exception.
On Windows, if a variant references a COM interface, any attempt to convert it reads
the object’s default property and converts that value to the requested type. If the
object has no default property, an exception is raised.
Variants in expressions
All operators except ^, is, and in take variant operands. Except for comparisons,
which always return a Boolean result, any operation on a variant value returns a
variant result. If an expression combines variants with statically-typed values, the
statically-typed values are automatically converted to variants.
This is not true for comparisons, where any operation on a Null variant produces a
Null variant. For example:
V := Null + 3;
assigns a Null variant to V. By default, comparisons treat the Null variant as a unique
value that is less than any other value. For example:
If Null > -3 Then... Else...;
string
converts to
integer,
truncating if
necessary; raises
exception if
string is not
numeric
converts to
real using
regional
settings; raises
exception if
string is not
numeric
converts
string/
character
formats
returns False if string is
“false” (non–case-sensitive)
or a numeric string that
evaluates to 0, True if string
is “true” or a nonzero
numeric string; raises
exception otherwise
character
same as string
(above)
same as string
(above)
same as string
(above)
same as string (above)
Boolean
False = 0,
True = –1
(255 if Byte)
False = 0,
True = –1
False = “0”,
True = “–1”
False = False,
True = True
Unassigned
returns 0 returns 0 returns empty
string
returns False
Null
raises exception raises
exception
raises
exception
raises exception
Table 5.7 Variant type conversion rules (continued)