给你个例子:
var
mybutton:TButton;
beign
mybutton:=TButton.create(Form1);
with mybutton do begin
Parent:=Form1;
Name:='mybutton';
caption:='动态控件';
width:=80;
height:=30;
left:=10;
top:=10;
end;end;
运行就可以看到一个按钮了。
控件数组嘛,那就看是怎么定义的了。例如:
var
mybutton:array[1..5] of TButton;你可以象数组一样用控件了,
例如
mybutton[1].caption:='按钮1';呵呵,希望对你有帮助。
var
mybutton:TButton;
beign
mybutton:=TButton.create(Form1);
with mybutton do begin
Parent:=Form1;
Name:='mybutton';
caption:='动态控件';
width:=80;
height:=30;
left:=10;
top:=10;
end;end;
运行就可以看到一个按钮了。
控件数组嘛,那就看是怎么定义的了。例如:
var
mybutton:array[1..5] of TButton;你可以象数组一样用控件了,
例如
mybutton[1].caption:='按钮1';呵呵,希望对你有帮助。
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure Hello(Sender:TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var ButtonArray:Array of TButton;
var i:integer;
begin
SetLength(ButtonArray,3);
For i:=0 to 2 do
begin
ButtonArray[i]:=TButton.Create(self);
ButtonArray[i].Caption:=inttostr(i);
ButtonArray[i].Left:=i*20;
ButtonArray[i].Top:=i*20;
ButtonArray[i].Parent:=Form1;
ButtonArray[i].OnClick:=Hello;
ButtonArray[i].Visible:=True;
end;
end;procedure TForm1.Hello(Sender: TObject);
begin
ShowMessage('hello');
end;end.
可以用tstringlist,还能定义个自己的名字,
呵呵,还可以根据名字排序。不过没有什么用处。procedure TForm1.Button3Click(Sender: TObject);
var
strings:TStringlist;
begin
strings.AddObject('asdf', TObject(TButton));
end;
var
strings:TStringlist;
begin
strings := TStringlist.Create;
strings.AddObject('asdf', TObject(TButton));
end;