将100个BUTTON的Click指向同一个事件,在这个事件中加入代码:
TButton(Sender).Caption := timetostr(time) ;

解决方案 »

  1.   

    如何把100个button的click事件指向同一个事件?
      

  2.   

    for i:=1 to 100 do
    with findcomponent(button+inttostr(i)) as Tbutton do
    click:=yourevent//让每个click事件指向同一事件
      

  3.   

    在你想要写的事件里如下写下便可以了,只用写一次,不过,好像很是浪费内存
    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;
      

  4.   

    不好意思,少写了一点,应该是:
    补全了
    结分吧
    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;
      

  5.   

    我晕~~~~~
    不好意思
    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;
    这下没错了
      

  6.   

    如果你认为浪费内存,那你为什么不用 Self.controls还有楼上的楼上那位 attacker2000(沙漠军刀)的 'Button'写成了 buttonOnClick写成了Click;这样可不好