2

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

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

thank you so much! fixed everything. I need to brush up on my parameter definitions.
You probably need to brush up on typing too. Your parameter did not have a type. That is cool in some dynamically typed languages, but not in Pascal/Delphi.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.