Zakładając, że CheckBox ma w polu Tag wartość N, odpowiadającą komponentowi EditN, to możesz to zrobić tak: wspólna akcja dla wszystkich CheckBox'ów (długie, ale idiotoodporne):
procedure TForm1.CheckBoxClick(Sender: TObject);
var Component:TComponent;
begin
if not (Sender is TCheckBox) then exit;
Component:=FindComponent('Edit'+IntToStr(TCheckBox(Sender).Tag));
if (Component<>nil) and (Component is TEdit) then
TEdit(Component).Visible:=TCheckBox(Sender).Checked;
end;
Możesz też tak:
if Sender=CheckBox1 then Edit1.Visible:=CheckBox1.Checked;
if Sender=CheckBox2 then Edit2.Visible:=CheckBox2.Checked;
Mniej uniwersalne ale krótsze.
function Ilosc(WinControl:TWinControl):integer;
var i:integer;
begin
result:=0;
for i:=0 to WinControl.ControlCount-1 do
begin
if (WinControl.Controls[i] is TWinControl) then
inc(result, Ilosc(TWinControl(WinControl.Controls[i])));
//Szukanie komponentów klasy TEdit
if (WinControl.Controls[i] is TEdit) then
inc(result);
end;
end;
procedure TForm1.ButtonClick(Sender: TObject);
begin
Caption:=IntToStr(Ilosc(self));
end;