var
Control:Array[1..20] of TButton;
I:Integer;
begin
for I:=1 To 20 do
begin
Control:=TButton.Create(Application);
Control.Parent:=Application.MainForm;
Control.Left:=I*100;
Control.Caption:=IntToStr(I);
end;
end;
不知道我的理解对不对
比如有10个按钮(button[1-10]),把CAPTION依次改为1到10:
procedure TForm1.OK_ButtonClick(Sender: TObject);
var i:integer;
begin
for i:=1 to 10 do
TButton(Form1.FindComponent('button'+inttostr(i))).caption:=inttostr(i);
end;
implementation
{$R *.DFM}
var
xButtons: array [1..20] of TButton;
// ...
procedure TForm1.FormCreate(Sender: Tobject);
var
I: Integer;
begin
for I:=1 to 20 do begin
xButtons:= TButton(FindComponent('Button'+ IntToStr(I)));
xButtons.Tag:= I;
end;
end;
以后使用时就以 xButtons[X] 来引用你的按键,按键例程里可以这样
procedure TForm1.ButtonClick(Sender: Tobject);//假定这20个按键的OnClick都连在这里
var
xButton: TButton;
ButtonID: Integer;
begin
xButton:= (Sender as TButton);
ButtonID:= xButton.Tag;
// ...
end;