50个checkbox 要求判断你选择了那个,并且把选择的checkbox的caption赋值给一个text里面麻烦大家帮忙,谢谢

解决方案 »

  1.   

    if checkbox 1.Checked then begin
    end;
    ................
    ................
     if checkbox n.Checked then begin
    end
      

  2.   

    var
     i:integer;i:=0;
    for i:=1 to 50 do
    begin
    if (FindComponent('cmb'+inttostr(i)) as TCombobox).itemindex<>-1) then
    begin
        edit1.text:=(FindComponent('cmb'+inttostr(i)) as TCombobox).selected.items[(FindComponent('cmb'+inttostr(i)) as TCombobox).itemindex];
    end;
    end;
      

  3.   

    edit1.text:=(FindComponent('cmb'+inttostr(i)) as TCombobox).items[(FindComponent('cmb'+inttostr(i)) as TCombobox).itemindex];
      

  4.   

    或者把每个CheckBox的OnClick指向同一个事件
    procedure CheckBoxClick(Sender as TObject);
    begin
      if Sender is TCheckBox then
      begin
        //一个变量记录是哪个CheckBox
        FSelected := Sender as TCheckBox;
        Edit.Text := FSelected.Caption;
      end;
    end;
      

  5.   

    for count:=0 to 组件容器.ControlCount -1 do
        begin
           if 组件容器.Controls[count] is Tcheckbox then
             begin
                 if  (组件容器.Controls[count] as Tcheckbox).checked then
                  edit1.text:=(组件容器.Controls[count] as Tcheckbox).caption
             end;
        end;
      

  6.   

    当你选择的时候,设置一个全局变量 SSS:TCheckBox每次选中CheckBox的时候,设置这个SSS= CHeckBox1[N]你每次判断的时候,就只判断 SSS就行了!
      

  7.   

    Procedure TForm1.Button1click(Sender:TObject);
    var
    Index:Integer;
    Begin
    For Index:=0 to ControlCount-1 do
    Begin
    if Components[Index] is Tcheckbox then
    if (Components[Index] As Tcheckbox).Checked then
    memo1.Lines.Add( (Components[Index] As Tcheckbox).caption);
    end;
    End;
      

  8.   

    或者把每个CheckBox的OnClick指向同一个事件
    procedure CheckBoxClick(Sender as TObject);
    begin
      if Sender is TCheckBox then
      begin
        //一个变量记录是哪个CheckBox
        FSelected := Sender as TCheckBox;
        Edit.Text := FSelected.Caption;
      end;
    end;
    这个我觉得比较好啊,因为我们可以共享事件代码,只需写一次而且节省时间.
      

  9.   

    var
    Index:Integer;
    Begin
    For Index:=0 to ControlCount-1 do
    Begin
    if Components[Index] is Tcheckbox then
    if (Components[Index] As Tcheckbox).Checked then
    memo1.Lines.Add( (Components[Index] As Tcheckbox).caption);
    end;
      

  10.   

    只是广告
    请大家支持下。。谢谢!
    http://community.csdn.net/Expert/topic/3632/3632147.xml?temp=.2835962
    http://community.csdn.net/Expert/topic/3607/3607671.xml?temp=.128689