问题:我现在根据业务的增加减少会自动生成一些控件,但是这些控件的响应函数如何编写?
举个例子,现在有三个业务,我动态生成了三个button,那么对应的三个onclick事件如何编写?
while(...)
begin
button:=TButton.create(self);
button.left:=10;
button.top:=100;
....
end;我点击这些button的事件该放在哪里?
举个例子,现在有三个业务,我动态生成了三个button,那么对应的三个onclick事件如何编写?
while(...)
begin
button:=TButton.create(self);
button.left:=10;
button.top:=100;
....
end;我点击这些button的事件该放在哪里?
解决方案 »
- 出售本人知识
- 诚聘Delphi中级程序员(管理软件方向,杭州)
- ado连接数据方法问题!
- 系统用了快一年了,才发现这个问题
- 请大家给个方法 如何用delphi通过网页操作数据库?
- 在DLL中动态不能创建TADOQuery问题,请指点指点
- 如何用Application.OnMinimize定制最小化事件?
- 为什么我点了dbgrid中的一行,前面也出现了一个小黑三角,可dbgrid1.SelectedRows.Count总是为0?
- 买了一本烂书,巨不爽,特此申明!!
- 有谁用过Wingate3.0作代理服务器的?
- fastreport里面怎么加上下标?
- Delphi6,WebSnap怎样实现图表统计???
type
TForm1 = class(TForm)
...
private
{ Private declarations }
public
{ Public declarations }
procedure test(Sender: TObject) ; //这里
end;
在implementation下写出它的实现如:
procedure TForm1.test(Sender: TObject) ;
begin
Showmessage('ok');
end;
然后:
button.OnClick:=test;就可以了
procedure ButtonClick(Sender: TObject);
OnMouseDown事件
procedure ButtonMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
这样可以根据需要传递参数。(上面过程的Button、Shitf、X、Y都可以传递)
1、从TButton继承一个新的TNewButton,增加属性,存放你的变量
2、建立数组,把参数放到数组里,然后根据Button的tag读取数组中的相应信息
如你个更明显的例子:改上面的test为
procedure test(Sender: TObject;var Key: Char); //这里
...
procedure TForm1.test(Sender: TObject;var Key: Char);
begin
Showmessage(Key);
end;
然后设
button.OnKeyPress:= test;
你选中新的button,按一键,就会显示该键
---------------------------------------------
不同的事件有不同的参数.看一下help文档就知道了