delphi 循环遍历Group box 获取内所有控件、控件属性等

//获取其他勾选项的Edit内容

function TForm1.GetQtText(gb1 : TGroupBox;EtName : string ) :WideString;
var
  i : integer;
begin
  Result:='';
  for i:=0 to gb1.ControlCount-1 do
    begin
      if gb1.Controls[i] is TEdit then
      begin
        if TEdit(gb1.Controls[i]).Name = EtName+'_qt' then
        begin
          Result:=TEdit(gb1.Controls[i]).text;
        end;
      end;
    end;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
i,j:Integer;
s,s1:string;
begin
  s := '';
  s1 :='';

//循环遍历groupbox的内容
  for j:=0 to length(arrayGroupbox)-1 do
  begin
    for i:=0 to arrayGroupbox[j].ControlCount-1 do
    begin

//判断是否为checkbox     也可以去做别的判断
      if arrayGroupbox[j].Controls[i] is TCheckBox then
      begin

//判断名称name是否为7位
        if length(TCheckBox(arrayGroupbox[j].Controls[i]).Name) = 7 then
        begin
          if s1<> '' then
          begin
            showmessage(s1+'x'+s);
            s1 :='';
            s  :='';
          end;
          if TCheckBox(arrayGroupbox[j].Controls[i]).Checked then
          begin
            if  TCheckBox(arrayGroupbox[j].Controls[i]).caption = '其他'  then
            begin

//当checkbox为其他时候,要保存其对应edit的内容  用其他-  来标识
              s1 :=  TCheckBox(arrayGroupbox[j].Controls[i]).caption + '-'+GetQtText(arrayGroupbox[j],TCheckBox(arrayGroupbox[j].Controls[i]).Name)   ;
            end else
            begin
              s1 := TCheckBox(arrayGroupbox[j].Controls[i]).caption;
            end;
          end;
        end else
        begin
          if TCheckBox(arrayGroupbox[j].Controls[i]).Checked then
          begin
            if TCheckBox(arrayGroupbox[j].Controls[i]).caption = '其他'  then
            begin

//判断s是否为空   判断完之后  通过s来赋值
              if s ='' then
              begin
                s :=  TCheckBox(arrayGroupbox[j].Controls[i]).caption + '-'+GetQtText(arrayGroupbox[j],TCheckBox(arrayGroupbox[j].Controls[i]).Name)   ;
              end else
              begin
                s := s + ';'+ TCheckBox(arrayGroupbox[j].Controls[i]).caption + '-'+GetQtText(arrayGroupbox[j],TCheckBox(arrayGroupbox[j].Controls[i]).Name)  ;
              end;
            end else
            if s ='' then
            begin
              s :=  TCheckBox(arrayGroupbox[j].Controls[i]).caption  ;
            end else
            begin
              s := s + ';'+ TCheckBox(arrayGroupbox[j].Controls[i]).caption ;
            end;
          end;
        end;
      end;
    end;
  end;

end;

//formshow的时候,为groupbox定义数组,为多个的时候方便遍历groupbox

procedure TForm1.FormShow(Sender: TObject);
begin
  ArrayGroupBox[0] := GroupBox4;
  ArrayGroupBox[1] := GroupBox5;
end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值