控件的动态创建后,他的事件如何写; 例如:我动态创建一个按钮,他如何执行单击事件。原先静态创建时,直接在单击事件里写代码就行了,可动态创建,往哪里写啊。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 produce MyClick(Sender: TObject); //定义自己的单击事件produce MyClick(Sender: TObject); //实现begin //end;var button: TButton;begin button := TButton.Create(self); button.parent := self; button.caption := 'btn1'; button.click := MyClick; //给事件赋值 end; 同意一楼!,只是...button.OnClick := MyClick(Sender); // 先写一个事件,然后赋给它例如 1. 先定义一个过程 buttontest(里面的参数直接想写哪个控件就用对应事件的参数) 2. 之后 button.onclick := buttontes就可以了 例子如下://Unit1 Codeunit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; procedure ButtonClick(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.DFM}procedure TForm1.ButtonClick(Sender: TObject);begin TButton(Sender).Caption:='OnClick Event OK!';end;procedure TForm1.Button1Click(Sender: TObject);begin With TButton.create(Self) do begin parent:=Form1; OnClick:=ButtonClick; end;end;end. var button: TButton;begin button := TButton.Create(self); button.parent := self; button.caption := 'btn1'; button.left := 100; button.top := 200; button.onClick := MyClick; //给事件赋值 ---end; 一般的可以,如果类似于:控件的事件声明:………………Taa:procedure(param1,param2……)of object; ………………xx=class…………Faa:Taa;procedure aa:Taa read Faa write Faa;这样的如何给事件赋值 写错了,应该是控件的事件声明:………………Taa:procedure(param1,param2……)of object; ………………xx=class…………Faa:Taa;proprety aa:Taa read Faa write Faa;这样的如何给aa事件赋值 谢谢各位的积极回复==================================回复人: boatzm(晓舟)【塑料的玫瑰花】(●) 你试过了么?========================================回复人: yywulan(鬼见怕) 先自定义一个事件过程。然后在:=给它不就得了吗?------------------------------------------------- 能通过么?能给个例子么? unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); private procedure ButtonClick(Sender:TObject); public { Public declarations } end;var Form1: TForm1; i:integer=1;implementation{$R *.dfm}procedure TForm1.ButtonClick(Sender: TObject);begin ShowMessage((Sender as TButton).Caption);end;procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);var tmpbutton:TButton;begin if Button=mbLeft then begin tmpbutton:=TButton.Create(self); tmpbutton.Parent:=Self; tmpbutton.Name:='Button'+IntToStr(i); tmpbutton.Caption:='Button'+IntToStr(i); tmpbutton.OnClick:=ButtonClick; tmpbutton.Left:=X; tmpbutton.Top:=Y; Inc(i); end;end;end. to hare007(横刀立马) ???一直这么用的呀?大量使用,怎么了? delphi encrpy 小系统的开发 Activx释放问题,不仅仅DAX Error,有挑战 数据导入 新年了,给大家散点分吧,分帖三 关于打印报表到最后几页时如何去除列标题的疑难---请高手相助 delphi有类似pb的datawindow的saveas功能的控件,可以将数据集保存为dbf或excel等其他格式吗?? 谁有delphi5的注册码,谢谢 谢谢各位,sorry.刚才我说的不太准确 help! I'm new. 关于all的问题? 请问有没有HP打印机1012和联想打印机3110耗材的替代产品,价格多少?
produce MyClick(Sender: TObject); //实现
begin
//
end;
var
button: TButton;
begin
button := TButton.Create(self);
button.parent := self;
button.caption := 'btn1';
button.click := MyClick; //给事件赋值
end;
例如
1. 先定义一个过程 buttontest(里面的参数直接想写哪个控件就用对应事件的参数)
2. 之后 button.onclick := buttontes就可以了
//Unit1 Code
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure ButtonClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.ButtonClick(Sender: TObject);
begin
TButton(Sender).Caption:='OnClick Event OK!';
end;procedure TForm1.Button1Click(Sender: TObject);
begin
With TButton.create(Self) do
begin
parent:=Form1;
OnClick:=ButtonClick;
end;
end;end.
button: TButton;
begin
button := TButton.Create(self);
button.parent := self;
button.caption := 'btn1';
button.left := 100;
button.top := 200;
button.onClick := MyClick; //给事件赋值 ---
end;
控件的事件声明:
………………
Taa:procedure(param1,param2……)of object;
………………
xx=class
…………
Faa:Taa;
procedure aa:Taa read Faa write Faa;
这样的如何给事件赋值
控件的事件声明:
………………
Taa:procedure(param1,param2……)of object;
………………
xx=class
…………
Faa:Taa;
proprety aa:Taa read Faa write Faa;
这样的如何给aa事件赋值
回复人: boatzm(晓舟)【塑料的玫瑰花】(●)
你试过了么?
========================================
回复人: yywulan(鬼见怕)
先自定义一个事件过程。然后在:=给它不就得了吗?
-------------------------------------------------
能通过么?能给个例子么?
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
procedure ButtonClick(Sender:TObject);
public
{ Public declarations }
end;var
Form1: TForm1;
i:integer=1;
implementation{$R *.dfm}procedure TForm1.ButtonClick(Sender: TObject);
begin
ShowMessage((Sender as TButton).Caption);
end;procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var tmpbutton:TButton;
begin
if Button=mbLeft then
begin
tmpbutton:=TButton.Create(self);
tmpbutton.Parent:=Self;
tmpbutton.Name:='Button'+IntToStr(i);
tmpbutton.Caption:='Button'+IntToStr(i);
tmpbutton.OnClick:=ButtonClick;
tmpbutton.Left:=X;
tmpbutton.Top:=Y;
Inc(i);
end;
end;
end.