原来见过类似这样的: case sender(x) of 1: 2: 3: ..... 上面那个 sender(x) 是啥就不记得了,是通过元件的tag属性来判别的.
if TButton(Sender) = Button1 then ... ;if TButton(Sender) = Button2 then ... ;
procedure TForm1.Button3Click(Sender: TObject); var i: Integer; begin for i:=1 to form1.ComponentCount do TButton(FindComponent('Button'+inttostr(i))).OnClick:=ButtonClick; end;procedure TForm1.ButtonClick(Sender: TObject); begin showmessage('ok'); end;
1:
2:
3:
..... 上面那个 sender(x) 是啥就不记得了,是通过元件的tag属性来判别的.
... ;if TButton(Sender) = Button2 then
... ;
var
i: Integer;
begin
for i:=1 to form1.ComponentCount do
TButton(FindComponent('Button'+inttostr(i))).OnClick:=ButtonClick;
end;procedure TForm1.ButtonClick(Sender: TObject);
begin
showmessage('ok');
end;
主要是在相同元件的tag属性设不同的序号,然后让它们的onclick事件指向
同一个程序,通过tag属性来判别是哪个元件的事件.
首先将多个button的tag依次设为0,1,2..
然后在其中一个button的Click事件中写如下代码:
procedure Tfmor1.btn1Click(Sender: TObject);
begin
case (sender as Tbutton).tag of
0:begin
...//do something
end;
1:begin
...
end;
2:begin
...
end;
3:
3:begin
...
end;
...
end;
end;
利用sender这个量,
(sender as tedit).lines.text:='dddd';
对sender进行判断就可以了!!
1:
2:
3:
end;
begin
case Longint(Sender) of
Longint(Button1) : ....
Longint(Button2) : ....
.
.
.
else ....
end;
end;
ehom(?!) 以后的朋友给出了正确的答案,谢谢!
不过我也结帖的时候,为啥老是说我的总分和不对啊?!
这样我无法结帖了 :(