我在一个窗体上用到了8个checkbox控件,请问我怎么用循环来控制这些控件的属性。
比如说,我要操作8个控件都不选,代码应该怎么写呢?
checkbox().checked := false;   ??????   //不知道如何写

解决方案 »

  1.   

    将8个CheckBox 声明为一个数组,类型为TCheckBox,然后循环数组就可以了!ArrCheck:Array [0..7]of TCheckBox; for i:=0 to 7 do TCheckBox(ArrCheck[i]).Checked := False;
      

  2.   

    用CheckListBox或
    将这些CheckBox放在一个GroupBox里,
    for i := 0 to GroupBox1.ControlCount - 1 do
    begin
      if GroupBox1.Controls[i] is TCheckBox then
        (GroupBox1.Controls[i] as TCheckBox).Checked := True;
    end;
      

  3.   

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

  4.   

    for i:=0 to ComponentCount-1 Do
        TCheckBox(FindComponent('CheckBox' + IntToStr(i))).Checked :=True;
      

  5.   

    将8个CheckBox 声明为一个数组,类型为TCheckBox,然后循环数组就可以了!ArrCheck:Array [0..7]of TCheckBox; for i:=0 to 7 do TCheckBox(ArrCheck[i]).Checked := False;==============================
    不行啊,有错,错误如下
    ---------------------------
    Debugger Exception Notification
    ---------------------------
    Project RemoteII.exe raised exception class EAccessViolation with message 'Access violation at address 0053E1C7 in module 'RemoteII.exe'. Read of address 00000000'. Process stopped. Use Step or Run to continue.
    ---------------------------
    OK   Help   
    ---------------------------
      

  6.   

    for i:=0 to ComponentCount-1 Do
        TCheckBox(FindComponent('CheckBox' + IntToStr(i))).Checked :=True;========================================
    谢谢了,搞定,结贴
      

  7.   

    再请教gxgyj(杰克.逊) ( ) :
      如果我是控制其它窗体的checkbox 呢?
    比如说是fmmain中的,又该怎么写呢?
    fmmain.TCheckBox(FindComponent('CheckBox' + IntToStr(i))).Checked :=True; 吗?
    这样好象不对。
      

  8.   

    for i:=0 to ComponentCount-1 Do    ////for i:=0 这里改为:for i:=1才行
        TCheckBox(FindComponent('CheckBox' + IntToStr(i))).Checked :=True;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    with fmmain do
      begin
      ..
      end;
      

  9.   

    TCheckBox(FindComponent('CheckBox' + IntToStr(i))).Checked :=True;
    这个前面加上form1,
     比如:
    Form4.TCheckBox(FindComponent('CheckBox' + IntToStr(i))).Checked :=True;
    他就不认识了阿,
    那如果不是在当前页面用这个checkbox又该怎么办呢??