在程序运行时,如何动态生成控件数组,控件数组已能创建,但不知如何响应事件??
程序中注释不知如何写才正常???unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure MyClick(Sender:TObject;index:integer);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var MB:array [0..5] of TEdit;
i:integer;
a:Tobject;
begin
for i:=0 to 5 do
begin
mb[i]:=Tedit.Create (Self);
mb[i].parent:=form1;
mb[i].top:=100;
mb[i].left:=100+i*150;
//mb[i].OnClick :=myclick(a,i); mb[i].Tag :=i;
mb[i].Show; end;
end;
procedure TForm1.MyClick (Sender:tobject;index:integer);
begin
showmessage(inttostr(index));
end;
end.
程序中注释不知如何写才正常???unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure MyClick(Sender:TObject;index:integer);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var MB:array [0..5] of TEdit;
i:integer;
a:Tobject;
begin
for i:=0 to 5 do
begin
mb[i]:=Tedit.Create (Self);
mb[i].parent:=form1;
mb[i].top:=100;
mb[i].left:=100+i*150;
//mb[i].OnClick :=myclick(a,i); mb[i].Tag :=i;
mb[i].Show; end;
end;
procedure TForm1.MyClick (Sender:tobject;index:integer);
begin
showmessage(inttostr(index));
end;
end.
解决方案 »
- 求助,很简单的问题,100分送上~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
- 【求助】dll 中如何 封装MDI 子窗体??
- 一段分析torrent文件bencoding数据的代码,总是莫名其妙出错,请帮忙看一下什么原因
- 隐藏和显示任务栏
- 在delphi中如何将array类型转化为string类型
- QR问题,大家帮忙!!
- 请问Delphi下边如何新建一个文件夹?
- 如何通过Form的Handle来创建一个TForm对象。
- 求救,我想找关于DELPHI6.0与COM+方面的书,请各位介绍几本,感激不尽
- 请假一个字符串操作函数
- NMSMTP控件发EMAIL问题(SMTP服务器需要身份验证)
- 我的关于BS结构的疑惑
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure MyClick(Sender:TObject;index:integer);//声明出错
//改为:procedure MyClick(Sender:TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var MB:array [0..5] of TEdit;
i:integer;
a:Tobject;
begin
for i:=0 to 5 do
begin
mb[i]:=Tedit.Create (Self);
mb[i].parent:=form1;
mb[i].top:=100;
mb[i].left:=100+i*150;
//mb[i].OnClick :=myclick(a,i);
//改为:mb[i].Onclick:=myclick(self);
mb[i].tag :=i; mb[i].Tag :=i;
mb[i].Show; end;
end;
procedure TForm1.MyClick (Sender:tobject;);
begin
showmessage(inttostr(TEdit(Sender).tag));//这里也要改
end;
end.