如果是判断checkbox有没有选中的问题``
  
  我只会判断2个哦```真失败!!!
  如果有很多很多个
那怎么去判断它有没有选中了
    有没有一些好提议呢?
 大家帮帮我
```

解决方案 »

  1.   

    if CheckBox1.Checked then 
       showmessage('checkbox1 選中了')
    else
       showmessage('checkbox1 沒有選中了')
    if CheckBox2.Checked then 
       showmessage('checkbox2 選中了')
    else
       showmessage('checkbox2 沒有選中了')   ...........
     
    if CheckBoxN.Checked then 
       showmessage('checkboxN 選中了')
    else
       showmessage('checkboxN 沒有選中了')
      

  2.   

    NONONO``````如果说给了个按钮你```
     你随便选中几个了
    点按钮就MEMO显示选中了哪几个没选了哪几个``
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
     i:integer;
    begin
    Memo1.Clear;
     for i:=0 to ComponentCount-1 do
     begin
       if Components[i].ClassName='TCheckBox' then
         if (Components[i] as TCheckBox).Checked then
           Memo1.Lines.Add(Components[i].Name);
     end;
    end;
      

  4.   

    keiy() 解释下代码的意思吗?
        看不明`````
    {for i:=0 to ComponentCount-1 do
     begin
       if Components[i].ClassName='TCheckBox' then
         if (Components[i] as TCheckBox).Checked then}这几段什么意思?
    Components,ComponentCount,ClassName 都有什么用途```
      

  5.   

    var i:integer;
        temp:tcomponent;
    begin
      for i:=componentcount-1 downto 0 do 
      begin
        temp:=components[i];
        if (temp is tcheckbox)then
        beign
          if (temp as tcheckbox).checked then
          {}
        end; 
      end;
    end;
    嘿嘿,不懂有没有写错~
      

  6.   

    貌似楼上有些东西和keiy是倒过来的`
    ``
    能解释下代码的意思吗?
        看不明`````
    {for i:=0 to ComponentCount-1 do
     begin
       if Components[i].ClassName='TCheckBox' then
         if (Components[i] as TCheckBox).Checked then}这几段什么意思?
    Components,ComponentCount,ClassName 都有什么用途```
      

  7.   

    在denlphi里面Components是一个系统变量,包含了当前窗口的一些vcl控件的信息,平时不常用但是对于需要循环遍历每个控件特别有用。这个可以说是个数组或者列表,里面包含了基本的vcl控件信息。你仔细看看所有delphi里面的事件里面有一个sender,就和那个一样 。也是可以转化后使用的。for i:=0 to ComponentCount-1 do //很显然从基数0开始遍历每一个控件
     begin
       if Components[i].ClassName='TCheckBox' then //判断这个控件的类名是不是TCheckBox也就是是否是你想判断的那个
         if (Components[i] as TCheckBox).Checked then} //对该控件进行强制转化以便使用该控件的方法和属性,在这里主要作为TCheckBox看看是否被选中
      

  8.   

    需要注意的就是该变量是针对当前窗口全局的,当你把所有按钮分为两组但你又只想判断其中一组的信息的时候需要你自己加工。所以如果你只想判断一部分按钮的话,你还要想别的方法,比如所有控件都有的tag值便是一个不错的注意
      

  9.   

    rcyboom(BOOM)   TAG属性怎用```
      我没用过哦``
    能说说么?
       
    Component有很多形式么?
    一些是ComponentCount,还是Components的?
     这个变量还有多少种形式呢??
      

  10.   

    楼主你对delphi里的继承关系还不是很清楚.for i:=0 to ComponentCount-1 do是遍历当前form的所有vcl组件if Components[i].ClassName='TCheckBox' then 就是如果遍历的时候当前的组件的类名是TCheckBox的话条件成立,也可以换成
    if Components[i].ClassType=TCheckBox then两句一样的效果if (Components[i] as TCheckBox).Checked then是判断当前组件(TCheckBox类型)是否被选中,也可以用下面的方式来写if TCheckBox(Components[i]).Checked then,后面你要怎么显示就看你自己喜欢了
      

  11.   

    楼上```DELPHI我刚学``有很多东西都不懂!TAG属性怎用```
      我没用过哦``
    能说说么?