if checkbox 1.Checked then begin end; ................ ................ if checkbox n.Checked then begin end
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;
edit1.text:=(FindComponent('cmb'+inttostr(i)) as TCombobox).items[(FindComponent('cmb'+inttostr(i)) as TCombobox).itemindex];
或者把每个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;
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;
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;
或者把每个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; 这个我觉得比较好啊,因为我们可以共享事件代码,只需写一次而且节省时间.
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;
................
................
if checkbox n.Checked then begin
end
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;
procedure CheckBoxClick(Sender as TObject);
begin
if Sender is TCheckBox then
begin
//一个变量记录是哪个CheckBox
FSelected := Sender as TCheckBox;
Edit.Text := FSelected.Caption;
end;
end;
begin
if 组件容器.Controls[count] is Tcheckbox then
begin
if (组件容器.Controls[count] as Tcheckbox).checked then
edit1.text:=(组件容器.Controls[count] as Tcheckbox).caption
end;
end;
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;
procedure CheckBoxClick(Sender as TObject);
begin
if Sender is TCheckBox then
begin
//一个变量记录是哪个CheckBox
FSelected := Sender as TCheckBox;
Edit.Text := FSelected.Caption;
end;
end;
这个我觉得比较好啊,因为我们可以共享事件代码,只需写一次而且节省时间.
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;
请大家支持下。。谢谢!
http://community.csdn.net/Expert/topic/3632/3632147.xml?temp=.2835962
http://community.csdn.net/Expert/topic/3607/3607671.xml?temp=.128689