Quick start manual

5-36
Delphi Language Guide
Variant types
In this example, the Else part of the If statement will be executed. This behavior can
be changed by setting the NullEqualityRule and NullMagnitudeRule global
variables. Refer to the CLX online documentation for more information.
Variant arrays
You cannot assign an ordinary static array to a variant. Instead, create a variant array
by calling either of the standard functions VarArrayCreate or VarArrayOf. For
example,
V: Variant;
ƒ
V := VarArrayCreate([0,9], varInteger);
creates a variant array of integers (of length 10) and assigns it to the variant V. The
array can be indexed using V[0], V[1], and so forth, but it is not possible to pass a
variant array element as a var parameter. Variant arrays are always indexed with
integers.
The second parameter in the call to VarArrayCreate is the type code for the array’s
base type. For a list of these codes, see the online Help on VarType. Never pass the
code varString to VarArrayCreate; to create a variant array of strings, use varOleStr.
Variants can hold variant arrays of different sizes, dimensions, and base types. The
elements of a variant array can be of any type allowed in variants except ShortString
and AnsiString, and if the base type of the array is Variant, its elements can even be
heterogeneous. Use the VarArrayRedim function to resize a variant array. Other
standard routines that operate on variant arrays include VarArrayDimCount,
VarArrayLowBound, VarArrayHighBound, VarArrayRef, VarArrayLock, and
VarArrayUnlock.
Note
Variant arrays of custom variants are not supported, as instances of custom variants
can be added to a VarVariant variant array.
When a variant containing a variant array is assigned to another variant or passed as
a value parameter, the entire array is copied. Don’t perform such operations
unnecessarily, since they are memory-inefficient.
OleVariant
The OleVariant type exists on both the Windows and Linux platforms. The main
difference between Variant and OleVariant is that Variant can contain data types that
only the current application knows what to do with. OleVariant can only contain the
data types defined as compatible with OLE Automation which means that the data
types that can be passed between programs or across the network without worrying
about whether the other end will know how to handle the data.