DYNAMIC ARRAY

DYNAMIC ARRAY data type works in the same way as ARRAY data type but it has some additional features.

As opposed to static arrays, dynamic arrays do not have a fixed size. When you add a new element to the dynamic array, it resizes automatically (whereas it is impossible to write beyond the bounds of a static array).

Dynamic arrays can be single- and multi-dimensional.

Single-dimensional arrays have this syntax:

4GL data type

any Querix 4gl or user-defined data type except for ARRAY and DYNAMIC ARRAY

Multi-dimensional arrays have this syntax:

4GL data type

any Querix 4gl or user-defined data type except for ARRAY and DYNAMIC ARRAY

integer expression

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

Here is a example of how two-dimensional dynamic arrays are declared:

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

Here is a example of how three-dimensional dynamic arrays are declared:

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

Restrictions imposed on dynamic arrays

There is a number of restrictions imposed on dynamic arrays.

getLength() method is not supported for a whole array - only for its separate elements:

For example, for a two-dimensional dynamic array:

DEFINE a DYNAMIC ARRAY WITH 2 DIMENTIONS OF datatype

valid usage is a[index].getLength(), and

invalid usage is a.getLength() (will cause in a compile time error).

DISPLAY ARRAY can be used to display only arrays of the RECORD data type.

Array length must always be greater than 0. Otherwise, the program will fail to compile.

Using dynamic arrays

Dynamic arrays can be used in the DISPLAY ARRAY and INPUT ARRAY statements like static arrays. When used in the INPUT ARRAY statement, the array will be automatically resized when the cursor moves to a non-occupied row of the screen array as well as when the row is deleted.

Querix4GL also has a number of methods that can be used with variables of the DYNAMIC ARRAY data type:

variable.Method()

These methods serve as auxiliary tools used to manage the dynamic array effectively:

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

return the size 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()

removes all the elements

join()

concatenates all the elements of an array into a string

 

 

Contact Us

Privacy Policy

Copyright © 2024 Querix, (UK) Ltd.