ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage syntax / Declaring variables
  • Deallocating a dynamic array (optional)
  • Passing a dynamic array as parameter to a procedure
  • Declaring a dynamic array member
  • WLanguage functions and dynamic arrays
  • Limits: Elements of a dynamic array
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Dynamic array (Variable type)
In french: Tableau dynamique
A dynamic array is an "advanced" type of array: its dimensions are allocated on demand, as the program runs.. In most cases, a "simple" array is sufficient.
Reminder: An array is a structured type used to group together a series of elements of the same type.. Each element of the array can be accessed by its index.
It is recommended to use:
Example
// Déclarer un tableau dynamique
TableauClient is array dynamic
// Allouer un tableau dynamique
TableauClient is array dynamic

TableauClient = new array of 4 by 7 int
// Équivalent à: TableauClient = allouer un tableau de 4,7 entiers
// (A partir de la version 17) Équivalent à: TableauClient = allouer un tableau [4,7] entiers
// Faire référence à un tableau dynamique
TableauClient[2,5,3] = 47
// Équivalent à: TableauClient[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 be declared.

Allocating memory for a dynamic array (syntax 1)


<Nom du tableau dynamique> = allocate [an] array [ <Dimension 1> [,<Dimension 2>... [<Dimension 10>]] ] <Type des éléments du tableau>
Example:
TableauClient is array dynamic
TableauClient = new array [4,7] int

Allocating memory for a dynamic array (syntax 2) Hide the details

<Nom du tableau dynamique> = allocate [an] array of <Dimension 1> [by <Dimension 2>... [by <Dimension 10>]] <Type des éléments du tableau>

OR

<Nom du tableau dynamique> = allocate [an] array of <Dimension 1> [,<Dimension 2>... [,<Dimension 10>]] <Type des éléments du tableau>
<Name of dynamic array>:
Name of the dynamic array to be used. This array must have been declared previously.
<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 in the array. See The different WLanguage types.

Referencing a dynamic array

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

Referencing a one-dimensional dynamic array

<Array name>[Index1]

Referencing an element in a two-dimensional array:

<Array name>[Index1, Index2]

OR

<Array name>[index1][index2]

Referencing an element in an array with N dimensions

<Array name>[Index1,...,IndexN]

OR

<Array name>[Index1]...[IndexN]

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

<Procedure name>(<Array name>)
<Array name>:
Name of the dynamic array to be used.
<Index1>:
Index of the element for the 1st dimension.
<Index2>:
Index of the element for the 2nd dimension.
<IndexN>:
Index of the element for the Nth dimension (N <= 10).
Remarks

Deallocating a dynamic array (optional)

A dynamic array is automatically deallocated when the variable's lifetime ends (e.g., when the window is closed) or when new dimensions are allocated.
To deallocate a dynamic array, use the following syntax:
libérer <Nom du tableau dynamique>
If the dynamic array is declared and allocated in the same line of code, don't use the Delete keyword to deallocate the dynamic array. A runtime error will occur if Delete is used.

Passing a dynamic array as parameter to a procedure

A dynamic array can be passed as a parameter to a procedure. To do so, use the following syntax:
<Nom de la procédure>(<Nom du tableau>)
For example:
TableauFourn is array dynamic
TableauFourn = new array of 10 by 50 strings of characters
// Appel de la procédure AfficheTableau
AfficheTableau(TableauFourn)

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:
// Déclaration d'une structure
Struct is Structure
	x1 is int
	x2 is array dynamic		// Déclaration du tableau
END

// Déclaration d'une variable de type structure
MaStruct is Struct
// Allocation du tableau
x2 = new array dynamic of 4,7 int
For a class, the dynamic array must be declared in the class declaration and memory must be allocated in the class constructor.

WLanguage functions and dynamic arrays

Several WLanguage functions can be used to manipulate dynamic arrays. You can search and sort the contents of an array, etc. For more details, see Array functions.

Limits: Elements of a dynamic array

  • A dynamic array can include classes only if these classes have a constructor without parameters (or with optional parameters).
  • A dynamic array cannot include:
    • composite variables,
    • arrays.
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

Last update: 09/24/2024

Send a report | Local help