for I := 0 to ComponentCount -1 do begin if Components[I] is TCheckBox then begin if (Components[I] as TCheckBox).name = 'xxxxx' then begin (Components[I] as TCheckBox)的具体操作 end; end; end;
定义一个数组 checkboxs:array of TCheckBox;
同意一楼的。 同时楼主也可以利用TComponent的Tag属性,比如将所有的TCheckBox分为若干组for I := 0 to ComponentCount -1 do begin if Components[I] is TCheckBox then begin case (Components[I] as TCheckBox).tag of 1: //do something 2: //do something 3: //do something ...... end; end; end;
for I := 0 to ComponentCount -1 do
begin
if Components[I] is TCheckBox then
begin
if (Components[I] as TCheckBox).name = 'xxxxx' then
begin
(Components[I] as TCheckBox)的具体操作
end;
end;
end;
同意一楼的。
同时楼主也可以利用TComponent的Tag属性,比如将所有的TCheckBox分为若干组for I := 0 to ComponentCount -1 do begin
if Components[I] is TCheckBox then begin
case (Components[I] as TCheckBox).tag of
1: //do something
2: //do something
3: //do something
......
end;
end;
end;
//1. var
cb:array [0..12] of TCheckBox; //2.初始化
cb[0] := cbx0;
cb[1] := cbx1;
cb[2] := cbx2;
...
...
cb[12] := cbx12; //3.使用时,可以直接使用cb数组