类似于,系统用户
每个用户名用一个checkbox显示出来,动态创建一个系统用户,即自动添加一个checkbox控件,
然后可以全部选中checkbox,进行编辑、删除等操作。
请教各位,如何动态创建checkbox以及(假如我当前的checkbox数量是i,如何全部选中)
谢谢

解决方案 »

  1.   

    这个很简单吧,你可以将你创建得控件用TList对象来管理。
    CheckBox = TCheckBox.Create(self).self指当前Form
    CheckBox.Parent = 你要将控件放入得容器控件.
    如果你用TList管理你得控件,你只要AList.add(checkBox)即可将当前的。
      

  2.   

    你怎么不试用CheckListBox控件,在additional页里就有
      

  3.   

    对,你可以看一下CheckListBox,应该能满足你的需求!Delphi好像不支持控件数组的吧!
      

  4.   

    with TCheckBox.Create(self) do
    begin
      parent:=self;
      caption:='test';
      left:=100; //给出创建的checkbox的座标
      top:=200;
    end;
    全选
    for i:=0 to self.componentcount-1 do
      if self.components[i] is TCheckBox then
        TCheckBox(self.components[i]).Checked:=true;
      

  5.   

    这样的需求最好用TCheckListBox,好管理
      

  6.   

    可以加个name,比如“checkbox[i]”,好调用吧
      

  7.   

    你也可以用DBgridEh;他可以让你定义checkbox的;把字段的checkboxes属性设为True,然后把Title里面的caption设置为‘空格’,keylist设置为1 0 2就可以了
    //----全部选中
    procedure TfrmReckingNextYear.tbl_AllClick(Sender: TObject);
    begin
      OperationAll(1);
    end;
    //----全部取消
    procedure TfrmReckingNextYear.ToolButton1Click(Sender: TObject);
    begin
       OperationAll(0);
    end;
    //----实施全选或全清
    function TfrmReckingNextYear.OperationAll(AType :integer):smallint;
    var
      pm :Pointer;
      cdsCloneCursor: TClientDataSet;
    begin
      if not cdsReckingNextYear.Active then Exit;
      if cdsReckingNextYear.IsEmpty then Exit;  pm := cdsReckingNextYear.GetBook;  cdsReckingNextYear.First;
      if cdsReckingNextYear.State = dsEdit then
        cdsReckingNextYear.Post;
      cdsCloneCursor := TClientDataSet.Create(nil); //刻隆CDS,为了避免记录太多全选的界面问题  with cdsCloneCursor do
      try
        cdsReckingNextYear.CheckBrowseMode;
        CloneCursor(cdsReckingNextYear,False);    Filtered := False;
        Filter := ' balmoney > 0 ';
        Filtered :=True;    pm := GetBook;
        DisableControls;
        First;
        while not Eof do
        begin
          Edit;
          FieldByName('checkbox').AsInteger := AType;
          Post;
          Next;
        end;
      finally
        GotoBook(pm);
        EnableControls;
        free;
      end;
    end;