VarArrayCreate

Create a variant array

Declaration

Source position: variants.pp line 123

  function VarArrayCreate(const Bounds: Array of SizeInt; 
                         aVarType: tvartype) : Variant;
  function VarArrayCreate(const Bounds: pvararrayboundarray; 
                         Dims: SizeInt; aVarType: tvartype) : Variant;

Description

VarArrayCreate creates a (optionally multidimensional) array with upper,lower bounds specified in Bounds. The number of bounds (in case of a single array) must be even: 2 bounds for every dimension of the array are required. All elements of the array are of the same type. The following examples create a one-dimensional array with 10 elements

VarArrayCreate([0,9],varInteger);
 VarArrayCreate([1,10],varInteger);

The first array is 0-based, the second is 1-based. The following creates a 2-dimensional array:

VarArrayCreate([0,9,0,1],varInteger);
 VarArrayCreate([1,10,1,2],varInteger);

The first array is 0-based, the second is 1-based. Each array consists of an array of 2 elements.

The array can also be specified as a pointer to array of system.tvararraybound records, and a number of dimensions. The above 1-dimensional arrays can be specified as:

var
  B : tvararraybound;
begin
  b.elementcount:=10;
  B.lowbound:=0;
  VarArrayCreate(@B,1,varInteger);
  b.elementcount:=10;
  B.lowbound:=1;
  VarArrayCreate(@B,1,varInteger);

Errors

If an uneven amount of bounds is specified or the operating system failed to create the array, an exception is raised using VarArrayCreateError

See also

Name Description
VarArrayCreateError Raise an EVariantArrayCreateError error
VarArrayOf Create a variants array of a series of values