|Navigation: Language Reference > 3 - Variable Declarations > Data Declarations and Memory Allocation >====== Variable Size Declarations ======|
It is now possible to declare variables of STRING-like and DECIMAL/PDECIMAL types of variable size to the compiler.
Restrictions are the same as for variable-size arrays (see below): declarations are available in the procedure or routine local scope only, and all variables used in the expression must be known at the time of the variable's creation.
TestProc(200) !can also be an initialized variable
TestProc PROCEDURE(LONG VarLength)
VarString = 'String of up to 200 characters'
Consider the following example:
Element LONG(100) !assign number of elements
DynArray CSTRING(100),DIM(Element) !declare a variable length array
There are 3 restrictions when using this technique:
1) The dimensioned variable (Element) must be locally declared in the respective PROCEDURE or ROUTINE data section and have no STATIC, THREAD or EXTERNAL attributes applied.
2) The dimensioned variable can not be a field component of any compound structure (GROUP,QUEUE, CLASS, RECORD)
3) All variables used in dimension expressions must be initialized at the moment of array initialization, i.e., they must be declared with an initial value before the array declaration, or they must be declared in outer scope and receive a value before the call to the PROCEDURE or ROUTINE, or they can be a parameter of the PROCEDURE.