dav*_*per 0 delphi multidimensional-array
我有一个像这样的全局数组:
FExample = Class
private
MyArray: Array of Array of Integer;
End;
Run Code Online (Sandbox Code Playgroud)
我在代码中填写:
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;
Run Code Online (Sandbox Code Playgroud)
现在我想要在初始化之前设置第一个值之前的数组是空的.我需要做什么 ?
您可以通过一次调用来设置多维数组的长度
SetLength(MyArray, dim1, dim2 [, more dimensions]);
Run Code Online (Sandbox Code Playgroud)
重置阵列调用
SetLength(MyArray, 0);
SetLength(MyArray, dim1, dim2);
Run Code Online (Sandbox Code Playgroud)
一些方法:
MyArray := Nil;
Finalize(MyArray);
SetLength(MyArray, 0);
Run Code Online (Sandbox Code Playgroud)
PS请注意,数组的这种扩展是无效的。考虑TList <>和其他可能性。
PPS您没有显示真实代码