Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SetLength on multidimensional array

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.

like image 757
Jonathan Avatar asked Apr 03 '11 15:04

Jonathan


1 Answers

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.

like image 63
Andreas Rejbrand Avatar answered Sep 22 '22 00:09

Andreas Rejbrand