以下是動態建立控制元件 TButton 陣列,進行處理的程式碼示例:
procedure TForm1.Button1Click(Sender: TObject);
var
arrButton: array[1..10] of TButton;
i: Integer;
begin
for i := 1 to 10 do
arrButton[i] := TButton.Create(Self);
arrButton[i].Parent := Panel1;
if i
arrButton[i].Left := i*80;
arrButton[i].Top := 40;
end else
arrButton[i].Left := (i-5)*80;
arrButton[i].Top := 100;
end;
arrButton[i].onClick := ButtonClick;//按紐事件
執行結果:
以下是動態建立控制元件 TButton 陣列,進行處理的程式碼示例:
procedure TForm1.Button1Click(Sender: TObject);
var
arrButton: array[1..10] of TButton;
i: Integer;
begin
for i := 1 to 10 do
begin
arrButton[i] := TButton.Create(Self);
arrButton[i].Parent := Panel1;
if i
begin
arrButton[i].Left := i*80;
arrButton[i].Top := 40;
end else
begin
arrButton[i].Left := (i-5)*80;
arrButton[i].Top := 100;
end;
arrButton[i].onClick := ButtonClick;//按紐事件
end;
end;
執行結果: