2
votes

I made a program that has a procedure with an array as one of it's parameters

program something ;

const someArray: array[1..4] of integer = (1, 2, 3, 4);

procedure name(someArray: array; a, n: integer);
    begin
    ....
    end;

begin
name(someArray, x, y)
end.

After compiling the program I get an error: Fatal: Syntax error, OF expected but ; found (function name() is highlighted)

Why isn't this program working?

2
This question is already answered here: stackoverflow.com/questions/20057974/… - Alexander Baltasar
Open arrays are dialect dependent. If you use Delphi or something compatible like Lazarus the term is open array name(somearray:array of integer;...); - Marco van de Voort
Why are you naming your array argument to your function the same as your constant array (someArray)? Although scope may be understood, it unnecessarily introduces some confusion. - lurker

2 Answers

4
votes

You need to declare your parameter properly, as an open array. You find the bounds of the array by using Low and High.

Here's a (useless but working) example:

program Sample;
Var x,y: Integer;

const
  SomeArray: array[1..4] of Integer = (1, 2, 3, 4);

procedure Name(const AnArray: Array of Integer; const A, B: Integer);
var
  OutOne, OutTwo, i: Integer;
begin
  for i := Low(AnArray) to High(AnArray) do
  begin
    OutOne := AnArray[i] * A;
    OutTwo := AnArray[i] * B;
    WriteLn('One: ', OutOne, ' Two: ', OutTwo);
  end;
end;

begin
  //x and y have to be initialised before use
  Name(SomeArray, x, y);
  ReadLn;
end.
2
votes

To complement Ken White's answer, in straight up (pre-open array) Pascal, array on its own in a parameter definition is unsupported.

Instead you need to declare a specific array type to do what you are trying to do here.

Here's what that could look like:

program something ;

type
  TMyArray = array[1..4] of integer;

const someArray: TMyArray = (1, 2, 3, 4);

procedure name(someArray: TMyArray; a, n: integer);
    begin
    ....
    end;

begin
name(someArray, x, y)
end.