Some variable arrays may be resized at runtime.
You can define arrays so that you can resize them at runtime. Unlike a fixed array, a resizeable array array will only use as much memory as you need and may be removed from memory when you are done with the array.
When an array is resized, existing array element values are not affected. This means that an array of ten elements which is resized to five elements will contain the same values in elements 0 to 4 that it contained before the resize operation. If the same ten element array is resized to twenty elements, then elements 0 to 9 contain the same values they had before the resize operation and elements 10 to 19 will contain default initial values for the data type of the array.
You create a resizeable array be defining an array variable with a count of zero for each dimension. Before you use the array in your code you must call the _resizeArray() function and set the size of each dimension in the array. See _resizeArray() function. The _getArrayLength() function returns the number of elements in an array at runtime See _getArrayLength() function.
Note: You cannot resize a state variable array.
You can clear a resizeable array by using the _resizeArray() function to set all of its dimensions to zero.
The array variable to be resized must be a standard variable (not a state variable) declared with a 0 count for each dimension of the array. When resizing an array, you must provide a count of 1 or greater for each dimension of the array or provide a count of 0 for all dimensions of the array. You cannot resize an array with a mix of zero and non-zero dimension counts and you cannot provide negative dimension counts.
Until you resize the array variable you cannot use it in an expression or set the value of an array element.
The following example declares a one dimensioned variable which can be resized. It is part of the timer.ujml sample.
<var name="mListeners" type="ITimerListener" size="0"/>
The following example shows how to resize the array variable declared above. It is part of the timer.ujml sample.
_resizeArray(mListeners, maxListeners);
The following example declares a two dimensioned variable which can be resized. It is part of the lifegrid.ujml sample.
<var name="mBlocks" type="ILifeBlock" size="0, 0"/>
The following example shows how to resize the array variable declared above. It is part of the lifegrid.ujml sample.
_resizeArray(mBlocks, mRows, mCols);
The following example gets the size of a one-dimensioned variable. It is part of the timer.ujml sample.
cnt = _getArrayLength(mListeners, 0);
|
Copyright (c) 2000-2007 UIEvolution, Inc. All rights reserved.
|
|
What do you think about this topic? Send feedback!
|