Sign in Join
FPDoc Onlineexperiment

VarArrayCreate function

In unit Variants

Create a variant array.

Declaration

pascal
function VarArrayCreate(const Bounds: Array of SizeInt = Int64; 
 aVarType: tvartype): Variant

Arguments

Bounds

Bounds for the array.

aVarType

Element type.

Function result

The new variant array.

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 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

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.