我有一个像这样的全局数组:
FExample = Class
private
MyArray: Array of Array of Integer;
End;
我在代码中填充它:
SetLenght(MyArray,Lenght(MyArray)+1);//The extension of the array now is 1
MyArray[High(MyArray)][0] := 3;
MyArray[High(MyArray)][1] := 3;
SetLenght(MyArray,Lenght(MyArray)+1);//The extension of the array now is 1
MyArray[High(MyArray)][1] := 31;
......
//The extension of the array now is maybe 14 or 28 or whatever and the second dimension also could be anyone.
SetLenght(MyArray,Lenght(MyArray)+1);
MyArray[High(MyArray)][0] := 2;
现在我想让数组像初始化之前一样空,设置第一个值。我该怎么做呢
您可以通过调用
来设置多维数组的长度SetLength(MyArray, dim1, dim2 [, more dimensions]);
重置数组调用
SetLength(MyArray, 0);
SetLength(MyArray, dim1, dim2);
一些方法:
MyArray := Nil;
Finalize(MyArray);
SetLength(MyArray, 0);
注:注意,这样逐个扩展数组是无效的。考虑TList<>和其他可能性。
P.P.S.你没有显示真正的代码