关于n个控件操作的问题

zseawq4 2002-02-28 04:37:41
比如,有一个form1,里面有100个button(button1,button2...button100),我想按下任意一个button时,让button.caption:=timetostr(time);可我不想在每个button.click里加这条语句,怎么解决?
...全文
40 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
qiubolecn 2002-03-01
  • 打赏
  • 举报
回复
如果你认为浪费内存,那你为什么不用 Self.controls

还有楼上的楼上那位 attacker2000(沙漠军刀)的 'Button'写成了 button

OnClick写成了Click;这样可不好
ihihonline 2002-03-01
  • 打赏
  • 举报
回复
我晕~~~~~
不好意思
procedure TForm1.someobjectEvents(Sender: TObject);
var
i:integer;
~~~~~~~~~ longint->integer
begin
for i:= 0 to form1.ComponentCount-1 do
begin
if (form1.Components[i] is Tbutton ) then
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ as->is
Tbutton(form1.Components[i]).caption:=timetostr(time);
end;

end;
这下没错了
ihihonline 2002-03-01
  • 打赏
  • 举报
回复
不好意思,少写了一点,应该是:
补全了
结分吧
procedure TForm1.Button4Click(Sender: TObject);
var
i:logint;
begin
for i:= 1 to form1.ComponentCount-1 do
begin
if (form1.Components[i] as tbutton ) then
Tbutton(form1.Components[i]).caption:=timetostr(time);
end;


end;
ihihonline 2002-02-28
  • 打赏
  • 举报
回复
在你想要写的事件里如下写下便可以了,只用写一次,不过,好像很是浪费内存
procedure TForm1.someobjectEvents(Sender: TObject);
var
i:logint;
begin
for i:= 1 to form1.ComponentCount-1 do
begin
Tbutton(form1.Components[i]).caption:=timetostr(time);
end;

end;
attacker2000 2002-02-28
  • 打赏
  • 举报
回复
for i:=1 to 100 do
with findcomponent(button+inttostr(i)) as Tbutton do
click:=yourevent//让每个click事件指向同一事件
zseawq4 2002-02-28
  • 打赏
  • 举报
回复
如何把100个button的click事件指向同一个事件?
Liujc 2002-02-28
  • 打赏
  • 举报
回复
将100个BUTTON的Click指向同一个事件,在这个事件中加入代码:
TButton(Sender).Caption := timetostr(time) ;

830

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧