for i:=0 to ComponentCount-1 do
 if Components[i] is TCheckBox then
 begin
   (Components[i] as TCheckBox )......
 end;

解决方案 »

  1.   

    procedure TForm1.CheckBox1Click(Sender: TObject);
    begin
      if sender is TCheckBox then
        TCheckBox(sender).Caption := TCheckBox(sender).Caption + inttostr(TCheckBox(sender).tag)
      else if Sender is TRadioButton then
        TRadioButton(Sender).Caption := TRadioButton(Sender).Caption + inttostr(TRadioButton(Sender).tag);
    end;procedure TForm1.FormCreate(Sender: TObject);
    var
      i: integer;
    begin
      for i := 0 to ComponentCount - 1 do
      begin
        if Components[i] is TCheckBox then
        begin
          TCheckBox(Components[i]).ONClick := CheckBox1Click;
          CheckBox1Click(Components[i]);
        end
        else if Components[i] is TRadioButton then
        begin
          TRadioButton(Components[i]).OnClick := CheckBox1Click;
          CheckBox1Click(Components[i]);
        end;
      end;
    end;
      

  2.   

    谢谢你,不过我的意思不是这样的,例如我要在oncreate中使用For计数,从1至3,使那六个选项框的tag值为1至3的显示,4-6就隐藏,如何做?
      

  3.   

    procedure TForm1.FormCreate(Sender: TObject);
    var
      i: integer;
    begin
      for i := 0 to Form1.ComponentCount - 1 do
      begin
          if (Components[i] is TCheckBox) or (Components[i] is TRadioButton) then
          if TButtonControl(Components[i]).Tag in [1..3] then
            TButtonControl(Components[i]).Visible := False
          else if TButtonControl(Components[i]).Tag in [4..6] then
            TButtonControl(Components[i]).Visible := True;
      end;
    end;
      

  4.   

    是这样吗?
    procedure TForm1.FormCreate(Sender: TObject);
    var
      i: integer;
    begin
      for i := 0 to Form1.ComponentCount - 1 do
      begin
        if (Components[i] is TCheckBox) or (Components[i] is TRadioButton) then
          if TButtonControl(Components[i]).Tag in [1..3] then
            TButtonControl(Components[i]).Visible := False
          else if TButtonControl(Components[i]).Tag in [4..6] then
            TButtonControl(Components[i]).Visible := True;
      end;
    end;
      

  5.   

    不好意思上面的写反了!
    procedure TForm1.FormCreate(Sender: TObject);
    var
      i: integer;
    begin
      for i := 0 to Form1.ComponentCount - 1 do
      begin
        if (Components[i] is TCheckBox) or (Components[i] is TRadioButton) then
          if TButtonControl(Components[i]).Tag in [1..3] then
            TButtonControl(Components[i]).Visible := True
          else if TButtonControl(Components[i]).Tag in [4..6] then
            TButtonControl(Components[i]).Visible := False;
      end;
    end;
      

  6.   

    对,就是这样子,但我的窗体上使用GroupBox框分开了几组按扭,以上的隐藏和显示我只想针对一组按钮,在tag相同name不同的情况下如何实现?
    万分感谢!!!
      

  7.   

    procedure TForm1.FormCreate(Sender: TObject);
    var
      i: integer;
    begin
    //对GroupBox1上的控件操作 
      for i := 0 to Form1.ComponentCount - 1 do
      begin    if (Components[i] is TCheckBox) or (Components[i] is TRadioButton) then
          if TButtonControl(Components[i]).Parent.Name = 'GroupBox1' then
            if TButtonControl(Components[i]).Tag in [1..3] then
              TButtonControl(Components[i]).Visible := True
            else if TButtonControl(Components[i]).Tag in [4..6] then
              TButtonControl(Components[i]).Visible := False;
      end;
    end;
      

  8.   

    for i:=GroupBox.ControlCount-1 downto 0 do
      (GroupBox.Controls[i] as TRadioButton).Visible :=False
      

  9.   

    Kingron(单身走我路……)写得更简洁!
      

  10.   

    procedure TForm1.FormCreate(Sender: TObject);
    var
      i: integer;
    begin
      for i := 0 to GroupBox1.ControlCount - 1 do
      begin
        if (GroupBox1.Controls[i] is TCheckBox) or (GroupBox1.Controls[i] is TRadioButton) then
          if GroupBox1.Controls[i].Tag in [1..3] then
            TButtonControl(GroupBox1.Controls[i]).Visible := True
          else if GroupBox1.Controls[i].Tag in [4..6] then
            TButtonControl(GroupBox1.Controls[i]).Visible := False;
      end;end;