PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • Freeing a dynamic array (optional)
  • Passing a dynamic array in parameter to a procedure
  • Declaring a dynamic array member
  • WLanguage functions and dynamic arrays
  • Limits: Elements of a dynamic array
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Dynamic array (Type of variable)
In french: Tableau dynamique (Type de variable)
A dynamic array is an "advanced" type of array: the dimensions of this array are allocated upon request during the execution of the program. In most cases, a "simple" array is sufficient.
Reminder: An array is a structured type that is used to group a set of elements of the same type. Each array element can be directly accessed by its subscript.
We advise you to use:
  • A dynamic array or a "simple" array when the size of the array must be modified during the program execution.
  • A fixed array for the Windows APIs.
  • An associative array to store the elements indexed on any type of information.
Versions 16 and later
Universal Windows 10 App This feature is available for the Windows Phone applications.
New in version 16
Universal Windows 10 App This feature is available for the Windows Phone applications.
Universal Windows 10 App This feature is available for the Windows Phone applications.
Versions 18 and later
Universal Windows 10 App This feature is available in Windows Store apps mode.
New in version 18
Universal Windows 10 App This feature is available in Windows Store apps mode.
Universal Windows 10 App This feature is available in Windows Store apps mode.
Versions 21 and later
Universal Windows 10 App This feature is available in Universal Windows 10 App mode.
New in version 21
Universal Windows 10 App This feature is available in Universal Windows 10 App mode.
Universal Windows 10 App This feature is available in Universal Windows 10 App mode.
Example
// Declare a dynamic array
CustomerArray is dynamic array
// Allocate a dynamic array
CustomerArray is dynamic array

CustomerArray = new array of 4 by 7 int
// Equivalent to: CustomerArray = new array of 4,7 int
// (From version 17) Equivalent to: CustomerArray = new array [4,7] int
// Refer to a dynamic array
CustomerArray[2,5,3] = 47
// Equivalent to: CustomerArray[2][5][3] = 47
Syntax

Declaring a dynamic array Hide the details

<Name of Dynamic Array> is dynamic array
<Name of dynamic array>:
Name of the dynamic array variable to declare.
Versions 17 and later

Creating a dynamic array


<Name of Dynamic Array> = new array [ <Dimension 1> [,<Dimension 2> ... [<Dimension 10>]] ] <Type of Array Elements>
Example:
CustomerArray is dynamic array
CustomerArray = new array [4,7] int
New in version 17

Creating a dynamic array


<Name of Dynamic Array> = new array [ <Dimension 1> [,<Dimension 2> ... [<Dimension 10>]] ] <Type of Array Elements>
Example:
CustomerArray is dynamic array
CustomerArray = new array [4,7] int

Creating a dynamic array


<Name of Dynamic Array> = new array [ <Dimension 1> [,<Dimension 2> ... [<Dimension 10>]] ] <Type of Array Elements>
Example:
CustomerArray is dynamic array
CustomerArray = new array [4,7] int
<Name of Dynamic Array> = new array of <Dimension 1> [by <Dimension 2> ... [by <Dimension 10>]] <Type of array elements>

OR

<Name of Dynamic Array> = new array of <Dimension 1> [,<Dimension 2> ... [,<Dimension 10>]] <Type of Array Elements>
<Name of dynamic array>:
Name of the dynamic array to use. This array was declared beforehand.
<Dimension 1>...<Dimension 10>:
Dimension 1 to 10 of the array (integer value equal to or greater than 0).
<Type of array elements>:
Type of the elements found in the array. See the different types of variables.

Referring to a dynamic array

Note: To refer to a dynamic array, this array must be allocated.

Referring to a one-dimensional dynamic array

<Array name>[Subscript1]

Referring to an element in a two-dimensional array:

<Array name>[Subscript1, Subscript2]

OR

<Array name>[Subscript1][Subscript2]

Referring to an element in an array with N dimensions

<Array name>[Subscript1,...,SubscriptN]

OR

<Array name>[Subscript1]...[SubscriptN]

Passing an array in parameter to a procedure: Hide the details

<Procedure name>(<Array name>)
<Array name>:
Name of the dynamic array to use.
<Subscript1>:
Subscript of the element for the 1st dimension.
<Subscript2>:
Subscript of the element for the 2nd dimension.
<SubscriptN>:
Subscript of the element for the Nth dimension (N <= 10).
Remarks

Freeing a dynamic array (optional)

A dynamic array is automatically freed at the end of the lifetime of the variable (when the window is closed for example) or when allocating new dimensions.
To explicitly free a dynamic array, use the following syntax:
delete <Name of Dynamic Array>
If the declaration and the allocation of the dynamic array are performed in a single code line, the Delete keyword must not be used to explicitly free the dynamic array. A runtime error will occur if Delete is used.

Passing a dynamic array in parameter to a procedure

A dynamic array can be passed in parameter to a procedure. To do so, use the following syntax:
<Procedure name>(<Array name>)
For example:
SupplierArray is dynamic array
SupplierArray = new array of 10 by 50 character strings
// Call to the DisplayArray procedure
DisplayArray(SuppArray)

Declaring a dynamic array member

A "dynamic array" member can be declared in:
  • a structure,
  • a composite variable,
  • a class.
The dynamic array must be allocated after the declaration of the structure or composite variable.
For example:
// Declare a structure
Struct is structure
        x1 is int
        x2 is dynamic array                // Declare the array
END

// Declare a structure variable
MyStruct is Struct
// Allocate the array
x2 = new dynamic array of 4,7 int
For a class, the declaration must be done in the declaration code of the class and the allocation must be done in the class constructor.

WLanguage functions and dynamic arrays

Several WLanguage functions can be used to handle the dynamic arrays. You have the ability to perform sorts, searches, ... See Functions for managing arrays for more details.

Limits: Elements of a dynamic array

  • A dynamic array can include classes only if these classes have a constructor without parameter (or with optional parameters).
  • A dynamic array cannot include:
    • composite variables,
    • arrays.
Java No array of classes or array of structures can be created.
Minimum version required
  • Version 9
This page is also available for…
Comments
Example Array [N,X]
//Example Array [N,X]

arrMensajes is array of 1 by 3 strings

i is int = 1

SQLExec(sQuery,ds)

WHILE SQLFetch(ds) = 0
arrMensajes[i,1] = SQLGetCol(ds, 1) //id
arrMensajes[i,2] = SQLGetCol(ds, 2) //numero
arrMensajes[i,3] = SQLGetCol(ds, 3) //mensaje
i++
Dimension(arrMensajes, i, 3)
END
BOLLER
17 Jul. 2019