Name
VarArrayCreate Function
Syntax
function VarArrayCreate(const Bounds: array of Integer;
VarType: Integer): Variant;Description
The VarArrayCreate function creates a
Variant array. The first argument specifies the
number of dimensions and the bounds for each dimension. The second
argument is the Variant type of each array
element.
The array bounds are specified as pairs of integers: the lower and
upper bounds of each dimension. The array can have up to 64
dimensions. If you try to create an invalid array,
VarArrayCreate reports runtime error 24
(EVariantError).
VarArrayCreate is a real function.
Tips and Tricks
Create a heterogeneous array by specifying
varVariantas the element type. That way, each element of the array can be of anyVarianttype.You cannot create an array of
varEmptyorvarNulltypes.
Example
// Return a Variant array of 12 random numbers.
function RandomDozen: Variant;
var
I: Integer;
begin
Result := VarArrayCreate([1, 12], varDouble);
for I := VarArrayLowBound(Result) to VarArrayHighBound(Result) do
Result[I] := Random;
end;See Also
| TVarArray Type, TVarArrayBound Type, VarArrayDimCount Function, VarArrayHighBound Function, VarArrayLock Function, VarArrayLowBound Function, VarArrayOf Function, VarArrayRedim Procedure, VarArrayRef Function, VarArrayUnlock Function, Variant Type, VarIsArray Function, VarType Function |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access