Arrays

Array is a formal group of several objects of the same type considered as a whole. The type of array can be any of available system types. If an array type is not specified, the Variant type is set, an array can store various types of values.

A variable can be defined as an array directly during this variable description, without prior description of the array type.

Var
    
myArray: Array; // Array of the Variant type

Array size can be set during variable description (static array) or during initialization in application code (dynamic array). Arrays consisting of one dimension are named one-dimensional arrays. If on defining the number of elements in the array dimension one number is used (without ".." characters), the length of the array dimension is set from 0 to the specified value. Array dimensions are determined by the Cartesian product of elements in each array dimension.

Const // Arrays range
    Min = -10;
    Max = 
10;
Var
    a: Array[Min..Max] 
Of Double; // One-dimensional array with explicit definition of array type
    b: Array[Min..Max, Min..Max]; // Two-dimensional array without explicit definition of array type (Variant by default)
    c: Array[55]; //Two-dimensional array with five elements in each dimension. Elements indexing in the range 0..4

Var
    myArray: Array 
Of Integer; // Determine data type in array
    myArray1: Variant; // Determine variable, which contains array
Begin
    
//...
    myArray := New Integer[1010]; // Create an array and determine its dimensions
    myArray1 := New Double[100]; // Create an array and determine its dimensions
    //...

As any type of data, arrays can be created and stored in variables of the Variant type. To work with elements, an array has to be obtained using the As operation, specifying the array type.

Var
    v: Variant;
    d: Array 
Of Double;
Begin
    v := 
New Double[3]; // Create a new array in variable of the Variant type
    d := v As Array Of Double; // Access to array elements
    d[0] := 1;
    d[
1] := 2;
    d[
2] := 3;
    v := d; 
// Reassign to change source variable

NOTE. If a dynamic array is overridden in the program body, all the data existing before the recreation is lost.

When arrays are assigned, data is copied. Dimensions and types of arrays must match for correct copying.

To address array elements, use the structure: myArray[<index> {, <index>}];

Var
    a: Array[
5Of Integer;
    b: Array 
Of Double;
Begin
    a[
0] := 100// Assign value to array element
    b := New Double[55];
    b[
00] := Double.MinValue; // Assign value to array element

See also:

Fore Language Guide