Dynamic Arrays

Dynamic arrays are used to handle multiple values of a single data type. Therefore each value is assigned to the specific index inside a list. An example dynamic int array with three values could look like this:

Index Value
1 7
2 23
3 13

The values can be addressed using the index of the array. It is to consider that a list has only one specific data type, e.g. int, uint, float, bool. To store multiple data types inside an array a dynamic anytype array must be used. For example:

Index Value
1 3,1415
2 "MyString"
3 TRUE
Anmerkung: Addressing an array without index causes a syntax error!

Following example describes how to create the two dynamic arrays from the description above and how to address a specific index inside the list.

main()
{
   dyn_int d_IntArray;
   dyn_anytype d_AnyArray;

   d_IntArray = makeDynInt(7,23,13);
   d_AnyArray = makeDynAnytype(3.1415,"MyString",TRUE);

   if(d_AnyArray[3])
   {
     DebugN(d_IntArray[2]); //Output: 23
   }
}                      

It is also possible to use multi dimensional arrays.

Example for an two-dimensional array and addressing elements inside the array.

main()
{
   dyn_dyn_int dd_IntArray;
   dd_IntArray[1] = makeDynInt(1,2,3);
   dd_IntArray[2] = makeDynInt(2,4,6);
   dd_IntArray[3] = makeDynInt(3,6,9);
   DebugN(dd_IntArray); //Output: The whole array
   DebugN(dd_IntArray[2]); //Output: 2,4,6
   DebugN(dd_IntArray[3][1]); //Output: 3
}

To change the value of an array element the corresponding index can directly addressed and the value can be set without changing the values of other list elements.

Following example describes how to set a value for an specific element inside a dynamic array.

main()
{
   dyn_int d_IntArray;

   d_IntArray = makeDynInt(7,23,13);
   DebugN(d_IntArray[2]); //Output: 23
   d_IntArray[2] = 42;
   DebugN(d_IntArray[2]); //Output: 42
} 

Dynamic Array Functions

Following functions are available for creating and manipulating dynamic arrays.