2016-04-26 22 views
1

我想創建,打印11個按鈕,所以我想用數組中的程序使用這些按鈕的唯一變化的是名稱添加值到帕斯卡爾的陣列 - iIllegal限定詞」

當我嘗試。編譯,我得到的錯誤「非法預選賽」在我的第一個數組賦值。

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 i:=0 to High(buttonName) do 
     begin 
      DrawButton(x, y, buttonName[i]); 
      y:= y+70; 
     end; 

請知道,我是很新的這和我不太瞭解我在數組,參數/常量等方面的知識。

謝謝

回答

1

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開頭。

+1

請記住更改主要部分! –

+1

非常感謝你!修好了一切。我需要刷新我的參數定義。 – denpa

+0

你可能還需要刷牙打字。你的參數沒有類型。這在一些動態類型的語言中很酷,但不在Pascal/Delphi中。 –