14个按钮的onclick有点不同,我想把代码进一步简化。1 4个按钮只需要一个事件处理过程, (20分)

  • 主题发起人 dxydudugo
  • 开始时间
D

dxydudugo

Unregistered / Unconfirmed
GUEST, unregistred user!
1 4个按钮只需要一个事件处理过程,在处理过程中判断哪
一个按钮按下了,然后做相应的显示过程。怎样才能实现上述过程。​
 
设置按钮的TAG属性为1、2、3、4......
到里卖难判断就行了。
procedure Form1.ButtonClick(Sender:TOBject);
begin
case TButton(Sender).Tag of
1:
begin
............
end;

end;
end;
 
procedure button1onclick(sender:tobject);
begin
if (sender.as tbutton).name='button1' then
begin
//
end;
if (sender.as tbutton).name='button2' then
begin
//
end;
end
 
同意wr960204
 
同意wr960204
 
可以[:)][:)]
 
我用这个办法做了一个400个按钮的软件,
 
procedure button1onclick(sender:tobject);
begin
if (sender.as tbutton).name='button1' then
begin
//
end;
if (sender.as tbutton).name='button2' then
begin
//
end;
end

使用运行期信息判断控件即可!
 
多人接受答案了。
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
877
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
顶部