Arrays

Top  Previous  Next

Creating arrays

 

PasScript allows to create single-dimensional arrays as well as multi-dimensional, allows to specify both: low bounds and high bounds of the array. The script program should use array constructor syntax to create array. For example:

 
a := array[0..5];       // Single-dimensional array.

a := array[0..71..3]; // Multi-dimensional array.

 

The low bound of the array is optional and can be omit. If the code omit low bound it set to zero by default:

 

a := array[5];    // Same as [0..5]

a := array[72]; // Same as [0..7, 0..2]

 

PasScript also supports creation of the arrays with elements of type other than varVariant. For example, it is possible to create an array with elements of varByte for more efficient data storage:

 

a := array[100] of Byte;

 

Following table specifies the list of type names that can be used in array constructor:

 

Type name

Variant value type code

Integer

varInteger

String

varOleStr

Double

varDouble

Single

varSingle

Boolean

varBoolean

Variant

varVariant

Byte

varByte

Word

varWord

LongWord

varLongWord

SmallInt

varSmallInt

Currency

varCurrency

ShortInt

varShortInt

Int64

varInt64

UInt64

varUInt64

Error

varError

Object

varDispatch

 

If the type name is omit, the array will be created with varVariant element type.

 

Using arrays

 

The script program should use square bracket syntax to access array elements, just like in Delphi:

 

a := array[0..10];
a[0] := 5;
a[1] := 7;
 
b := array[0..5, 0..7];
b[1, 3] := 11;
 
Y := a[0] + a[1] + b[1, 3];

 

The Length intrinsic function can be used to determine the length of the array. If the array is a multi-dimensional array, the dimension number can be specified as a second argument in a Length function call. The dimension numbers starts from 1. Here some examples:

 

a := array[0..10]
x := Length(a);
 
b := array[0..5, 0..7];
y := Length(b, 2);

 

The Low and High intrinsic functions can be used to determine the low and hight bounds of the array. Just like with Length function, the dimension number can be specified as a second argument:

 

a := array[0..10];
for i := Low(a) to High(a) do
  a[i] := i + 100;