What does it take to complete a multidimensional dynamic array?
I am using dynamic arrays and have no problem with the SetLength and Finalize procedures.
I recently had to use dynamic arrays where each element of the array could contain a variable number of elements. The declaration is like this:
TScheduleArray = array of array of array [1..DaysPerWeek] of TShiftType;
The software works great, I have no problem with how to use this framework. You call SetLength on the main array and then you can call SetLength again on each element in the array. This works as expected.
SetLength(MyArray, 1);
SetLength(MyArray[0], 2);
My question is this, when I came to free up the resources used for this array, I just call Finalize on the array variable:
Finalize(MyArray);
or should each element of the array be terminated as well, since each element is a dynamic array itself?
source to share
Quote : "You call SetLength on the main array and then you can call SetLength again every element of the array."
You don't need to iterate over your arrays.
SetLength()
takes a list of lengths for each dimension.
Example:
SetLength(ScheduleArray,200,15,35);
Same as:
SetLength(ScheduleArray,200);
for i:=low(ScheduleArray) to high(ScheduleArry) do
begin
SetLength(ScheduleArray[i],15);
for j:=low(ScheduleArray[i]) to high(ScheduleArray[i]) do
SetLength(ScheduleArray[i,j],35);
end;
source to share