//获取其他勾选项的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;