[Lazarus] procedure calls with variable sized arrays in parameter list?

Juha Manninen (gmail) juha.manninen62 at gmail.com
Fri Oct 8 15:04:19 CEST 2010


On Friday 08 October 2010 12:55:50 Bo Berglund wrote:
> procedure ChleskySolve(a: array of double; n: integer; p, b: array of
> double; var x: array of double);
> 
> The fortran specification indicates this concerning the arrays:
> a is really 2-dim: array[1..n][1..n] of double;
> p,b,x are 1-dim array[1..n] of double;
> 
> And x is the array holding the return values.
> 
> What is the correct declaration in this case? Open arrays can only be
> one-dimensional if memory serves me right.
> And do I need to declare var for the x array, or are they all supplied
> by reference?

Don't use open array parameters for the function.
Instead define types derived from dynamic arrays and use them everywhere.

type
  DoubleArray = array of Double;
  DoubleArray2 = array of array of Double;
...
procedure ChleskySolve(a: DoubleArray; ...

You can use SetLength for both dimensions :
  a2: DoubleArray2;
...
  SetLength(a2, 10);
  SetLength(a2[0], 10);


Juha




More information about the Lazarus mailing list