[next] [prev] [prev-tail] [tail] [up]

#### Open array parameters

Free Pascal supports the passing of open arrays, i.e. a procedure can be declared with an array of unspecified length as a parameter, as in Delphi. Open array parameters can be accessed in the procedure or function as an array that is declared with starting index 0, and last element index High(paremeter). For example, the parameter

     Row : Array of Integer;

would be equivalent to

     Row : Array[0..N-1] of Integer;

Where N would be the actual size of the array that is passed to the function. N-1 can be calculated as High(Row). Open parameters can be passed by value, by reference or as a constant parameter. In the latter cases the procedure receives a pointer to the actual array. In the former case, it receives a copy of the array. In a function or procedure, open arrays can only be passed to functions which are also declared with open arrays as parameters, not to functions or procedures which accept arrays of fixed length. The following is an example of a function using an open array:

     Function Average (Row : Array of integer) : Real;
     Var I : longint;
         Temp : Real;
     begin
       Temp := Row[0];
       For I := 1 to High(Row) do
         Temp := Temp + Row[i];
       Average := Temp / (High(Row)+1);
     end;

[next] [prev] [prev-tail] [front] [up]