delphi怎样遍历form1中的所有button控件

解决方案 »

  1.   

    而且我要知道当前焦点在哪个button控件,以及获得该button的name名称
      

  2.   

    var i:integer;
    begin
    for i:=0 to ComponentCount-1 do //得到窗体的所有控件。
      begin
       if Components[i] is TButton then //判断是否是TButton类。
    //     if TButton(Components[i]).Focused then  //判断是否有点焦
          showmessage(TButton(Components[i]).Name);
      end;
    end;
      

  3.   

    如果我想第i个button的cation为'我'
    但焦点不一定在这个button上,这语句该怎么写?
      

  4.   

    比如我想button3的Caption为'我',但焦点不一定在button3上这该怎么写
    有时又想button4的Caption为'我'
      

  5.   


    var i:integer;
    begin
    for i:=0 to ComponentCount-1 do //得到窗体的所有控件。
      begin
      if Components[i] is TButton then //判断是否是TButton类。
        if i=3 then
          TButton(Components[i]).Caption:='我';
      end;
    end;