SetLength on multidimensional array

隐身守侯 提交于 2019-12-23 07:36:52

问题


I'd like to know how to set the length of multidimensional arrays/create dynamic multidimensional arrays in Pascal. Like SetLength(arr,len) does for one dimensional arrays. I cannot find the answer.


回答1:


var
  arr: array of array of real;

...

SetLength(arr, 10, 20); // creates a 10 by 20 matrix

A bad, but equivalent, way of doing this is to do

SetLength(arr, 10);
for i := low(arr) to high(arr) do
  SetLength(arr[i], 20);

The latter approach allows "non-rectangular" arrays, however.



来源:https://stackoverflow.com/questions/5530606/setlength-on-multidimensional-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!