大家好,
在同一个窗口有六个checkbox,
现在我想用循环来判断checkbox1,checkbox2......是否checked
应该怎么写这个循环语句?

解决方案 »

  1.   

    var
      i: Integer;
    begin
      for i := 0 to self.ControlCount - 1 do
        if self.Controls[i] is TCheckBox then
          if TCheckBox(self.Controls[i]).Checked then
            有被选中的...
    end;
      

  2.   

    楼上的能解释一下吗
    Controls
      

  3.   

    用COMPONETS好一点,如果有CONTROLS的话,如果TCHECKBOX的parent不是self(formx)的话,那你的麻烦就大了
     luck!
      

  4.   

    var
      i: Integer;
    begin
      for i := 0 to panel1.ControlCount - 1 do
        if panel1.Controls[i] is TCheckBox then
          if TCheckBox(panel1.Controls[i]).Checked then
            有被选中的...
    end;
      

  5.   

    procedure TForm1.Button3Click(Sender: TObject);
    var
    i,a:integer;
    begin
      for i:=0 to Form1.ComponentCount-1 do
      begin
        if Form1.Components[i] is TEdit then
          Form1.Components[i].Visible:=false;///////这个不能通过
      end;
    end;Components与controls什么区别啊 ?
      

  6.   

    Form的事件内var
      i: Integer;
    begin
      for i := 0 to ComponentCount - 1 do
        if ((Components[i] is TCheckBox) and (Components[i] as TCheckBox).Checked) then
          有被选中的...
    end;
      

  7.   

    背书?看书可不是背书。学编程背书是没有用的。学会查书。Components和Controls的区别,看书看帮助看代码一看就知道。多看几次就理解了。背?背书的人真的很难学好编程。
      

  8.   

    在帮助的索引中输入:TComponent,Components看看解释:Lists all components owned by the component.property Components[Index: Integer]: TComponent;DescriptionUse Components to access any of the components owned by this component, such as the components owned by a form. The Components property is most useful when referring to owned components by number rather than name. It is also used internally for iterative processing of all owned components.Note: For convenience use Components with ComponentCount for iterative processing. However, be aware that while the ComponentCount of a component contains the same number of items as in the Components list for that component, ComponentCount is always 1 more than the highest Components index, because the first Components index is always 0. 输入:TWinControl,ControlsControls地解释:Lists all child controls. property Controls[Index: Integer]: TControl;DescriptionControls is an array of all the child controls. These are all controls that list this control as their Parent property. The Controls property is convenient for referring to the children of a control by number rather than name. For example, Controls may be used to iterate over all the child controls.Don't confuse the Controls property with the Components property. The Controls property lists all the controls that are child windows of the control, while the Components property lists all components that it owns. The form owns all components put on it, and therefore, they appear in the form's Components property list, even when they are child windows of a control on the form.Controls is a read-only property. To add or delete a child control, use the InsertControl or RemoveControl methods. To move a child control from one parent to another, set the Parent of the child control, as that will handle both the RemoveControl from the original parent and the InsertControl to the new parent.如果你说你英文不好,不爱看。那就算我没有说……
      

  9.   

    你生下来就什么都会啊
    5个星就牛X啊
    d里的所有class你都用通了,
    你你们牛X    你机器键盘是不是没有F1啊
    你来论坛从来没问过问题,就是为了回答问题和埋汰别人的吧