1
votes

It says

fatal: syntax error, OF expected but [ found" for the variable "lo"

But I really can't see whats wrong with it.
I tried to change variable name but seems not working.

procedure reg(     index, gen : char; 
                   fname, sname, loginname, passwords, pid : string; 
               var lo : array [1..26,1..1025] of bucket ; 
               var main : array[1..1025] of detail);
var
  convertedindex, i, j : integer;
  found, found2 : boolean;

It's supposed to be without error but it says syntax error.

3

3 Answers

3
votes

You can't define an array while you are in the middle of declaring the parameters of a procedure (or function). You need to define the array type beforehand by doing something like this instead:

program arraydecl;

type
  Bucket = integer;
  Detail = integer;

type
  BucketArray = array [1..26,1..1025] of Bucket;
  DetailArray = array[1..1025] of Detail;

procedure reg(index, gen : char; fname, sname, loginname, passwords, pid : string ; var lo :  BucketArray; var main : DetailArray);
begin
end; 
2
votes

The error message says that the compiler expected the keyword of, but instead it found an opening bracket [.

The reason is (I guess) that in procedure declarations, you cannot define the bounds of an array. For example, you cannot say main: array[1..2] of integer, you can only say main: array of integer.

You can try to define an array type and then use that type as the procedure parameter:

type TwoInts = array[1..2] of integer;

procedure PrintTwoInts(ti: TwoInts)
begin
  WriteLn(ti[1], ti[2])
end;

I haven't programmed in Pascal for a long time, so the above may or may not work. I don't remember whether ti would be passed by value or by reference, and whether the array indices inside the procedure would always start at 0. That's some things you would need to find out.

2
votes

Parameter lists

In some Pascal versions, like FreePascal or Delphi, parameter lists of functions or procedures cannot contain type declarations, only type specifications.

So, to specify such an array as parameter, you must declare its type first, before the function/procedure declaration:

type 
  // Type declarations
  Bucket = ... 
  Detail = ...
  TBuckets = array[1..26, 1..1025] of Bucket;
  TDetails = array[1..1025] of Detail;

procedure Reg(Index, Gen: Char; FName, SName, LoginName, Passwords, PID: string; 
  var Lo: TBuckets; var Main: TDetails);

Note that other Pascals (including ISO Pascal, if I remember correctly) do allow these ad hoc (on the spot) declarations, even in parameter lists. But obviously your dialect of Pascal doesn't.

Open array parameters

Now if you see a parameter specifications like x: array of Integer or similar, then you are dealing with open array parameters. This is not a declaration and it doesn't specify one single type, it accepts all kinds of one-dimensional arrays of that base type. More on that in my article Open array parameters and array of const.

This explains the error message: only of can follow array in a parameter list, to specify an open array parameter.


For what it's worth: if you are using FreePascal or Delphi, then you should get in the habit of passing strings as const, if possible: const FName, SName, etc...: string.