DYNAMIC ARRAY

 

DYNAMIC ARRAY data type works the same way as ARRAY data type, but it has some additional features. Use the following syntax to declare a single-dimensional dynamic array of variables:

 

 

Element

Description

4GL Data Type

Any Querix 4GL or user-defined data type except ARRAY, DYNAMIC ARRAY

 

Dynamic arrays differ from traditional 4GL program arrays in that they do not have a fixed size. Attempts to into a dynamic array will cause the array to resize automatically, whereas it is impossible to write beyond the bounds of a static program array.

 

A multi-dimensional dynamic array is declared using the following syntax:

 

 

Element

Description

4GL Data Type

Any Querix 4GL or user-defined data type except ARRAY, DYNAMIC ARRAY

Integer Expression

A 4GL expression returning a positive integer or a literal integer in the range from 1 to 3 which denotes the number of array dimensions

 

There exists a number of restrictions imposed on multi-dimensional dynamic arrays. They are as follows:

1.     .getLength() method is not supported. E.g., for:

 

DEFINE a DYNAMIC ARRAY WITH 2 DIMENTIONS OF datatype

 

valid usage:   

    

a[index].getLength()

 

invalid usage, resulting in a compile time error:  

 

a.getLength() 

 

2.     DISPLAY ARRAY statement can be used only for the arrays of the RECORD data type display.

 

3.     The same limitations as for the static arrays:

 

A two-dimensional dynamic array declaration:

 

DEFINE x DYNAMIC  ARRAY WITH 2 DIMENSIONS OF INTEGER

...

FOR i = 1 TO 100

FOR j = 1 TO 100

      LET x[i,j] = i*j MOD 7

END FOR

END FOR

 

A three-dimensional dynamic array declaration:

 

DEFINE x DYNAMIC  ARRAY WITH 3 DIMENSIONS OF INTEGER

...

FOR i = 1 TO 10

FOR j = 1 TO 10

FOR k = 1 TO 10

      LET x[i,j,k] = i*j*k MOD 13

END FOR

END FOR

END FOR

 

Here is the list of methods used to manipulate variables of a DYNAMIC ARRAY type:

 

append()

adds a new element after the last element of the array

appendElement()

adds a new element with the NULL value to the array (takes no parameters)

insert()

inserts a new array element to the specified position

insertElement()

inserts an empty array element to the specified position

resize()

resizes the single-dimensional array to the specified size

getSize()

returns the size of a single-dimensional array

getLength()

returns the length of a single-dimensional array

delete()

removes all the specified array elements within the given range or at the given position

deleteElement()

removes the specified array element

clear()

sets all the elements to NULL (in a static array) or removes all the elements (in a dynamic array)