向 Pascal 中的数组添加值 - iIllegal Qualifier”

Adding Values to an Array in Pascal - iIllegal Qualifier"

我正在尝试创建一个打印 11 个按钮的程序,所以我想使用一个数组。这些按钮的唯一变化是名称。

当我尝试编译时,我在第一次数组赋值时收到错误 "illegal qualifier"。

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;

主要是我正在尝试使用这个 for 循环

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

请知道,我对此很陌生,对我在数组方面的知识不太自信,parameters/calling 通过常量等。

谢谢

PopulateButton()参数定义错误

试试这个:

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;

还要注意命名约定。类型通常以 T 开头,函数参数以 A.

开头