button中的代码:
begin
form2 := tform2.create(self);
try
form2.show;//或form2.showmodal;
except
form2.free;
end;
end;
注意:别忘了在form的destroy事件中form2.free
begin
form2 := tform2.create(self);
try
form2.show;//或form2.showmodal;
except
form2.free;
end;
end;
注意:别忘了在form的destroy事件中form2.free
解决方案 »
- 关于组件中的“Strings”要怎么理解?
- 请问以下代码该如何理解?最好举个例子。
- 我想知道如何获得INI文件节名下面所有的KEY和值
- 随机数的问题:从数据库中取一个字段值,该字段是自动编号的。
- help ! about quickreport
- 散分呀!急!后天要交的!!关于2000下用delphi实现拨号的问题!
- 小弟刚学delphi,想学习一下三层结构,请问各位高手哪里有比较好的资料?
- 为什么我的程序发送短信的速度这么慢?急救。。。在线等候
- sql中有参数,是这么用吗?请指点.
- 关于delphi中sql7用户id的改变
- OpenFile怎么打开多个文件?
- 各位高手,关于DELPHI下多人协同开发软件的问题。
procedure TForm1.MyButtonClick(Sender: TObject);
begin
form2.show;
end;
然后
button1.onclick := MyButtonClick;
其他按钮类似
然后把你所动态建立的按钮的onclick赋值了这个过程就可以了。
比如:
procedure tform1.dothing(sender:tobject);
begin
//do your thing
end;
button1.onclick:=dothing;
注意,这个过程要以sender:tobject为形参.
{ Private declarations }
procedure MyClick(Sender: TObject);
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var i:integer ;
B_button:TButton ;
begin
for i:=1 to 10 do
begin
B_button:=Tbutton.Create(nil) ;
B_button.Parent := Panel1 ;
B_button.Name := 'B_But' + IntToStr(i);
B_button.Top := 2 ;
B_button.Left := (B_button.Width)*(i-1) ;
B_button.OnClick := MyClick ;
end;
end;procedure TForm1.MyClick(Sender: TObject);
begin
ShowMessage((Sender as TButton).Name);
end;
end.
{ Private declarations }
procedure MyClick(Sender: TObject);
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var i:integer ;
B_button:TButton ;
begin
for i:=1 to 10 do
begin
B_button:=Tbutton.Create(nil) ;
B_button.Parent := Panel1 ;
B_button.Name := 'B_But' + IntToStr(i);
B_button.Top := 2 ;
B_button.Left := (B_button.Width)*(i-1) ;
B_button.OnClick := MyClick ;
end;
end;procedure TForm1.MyClick(Sender: TObject);
begin
{ShowMessage((Sender as TButton).Name);}
form2.show;
end;
end.
var
button :array [0..15] of Tbutton;
I: Integer;
begin
for I ;= 0 to 15 do
begin
button[I] := tbutton.create(...);
...
...
button[I].tag := I;
button[I].onclick := myclick;
end;
end;procedure form1.myclick(Sender: TObject);
begin
case tbutton(sender).tag of
0: form2.show;
...
...
end;
end;