denpa
denpa

Reputation: 39

Adding Values to an Array in Pascal - iIllegal Qualifier"

I am trying to create a program that prints 11 buttons so I wanted to use an array. The only change with these buttons is the name.

When I try to compile, I get the error "illegal qualifier" at my first array assignment.

type 
buttonName = array[0..11] of String;

procedure PopulateButton(const buttonName);
begin
    buttonName[0] := 'Sequence';
    buttonName[1] := 'Repetition';
    buttonName[2]:= 'Modularisation';
    buttonName[3]:= 'Function';
    buttonName[4]:= 'Variable';
    buttonName[5]:= 'Type';
    buttonName[6]:= 'Program';
    buttonName[7]:= 'If and case';
    buttonName[8]:= 'Procedure';
    buttonName[9]:= 'Constant';
    buttonName[10]:= 'Array';
    buttonName[11]:= 'For, while, repeat';
end;

and in main I am trying to use this for loop

for i:=0 to High(buttonName) do 
        begin
            DrawButton(x, y, buttonName[i]);
            y:= y+70;
        end;

Please know, I am very new to this and am not too confident of my knowledge in arrays, parameters/calling by constant and such.

Thank you

Upvotes: 2

Views: 686

Answers (1)

ViRuSTriNiTy
ViRuSTriNiTy

Reputation: 5155

The parameter definition of PopulateButton() is wrong.

Try this:

type 
  TButtonNames = array[0..11] of String;

procedure PopulateButtons(var AButtonNames: TButtonNames);
begin
  AButtonNames[0] := 'Sequence';
  ...
end;

...

var lButtonNames: TButtonNames;

PopulateButtons(lButtonNames);

for i := Low(lButtonNames) to High(lButtonNames) do 
begin
  DrawButton(x, y, lButtonNames[i]);

  y:= y+70;
end;

Also pay attention to the naming conventions. Types normally begin with a T and function parameters start with an A.

Upvotes: 2

Related Questions