将Edit5-edit9的tag置为5-9(分别设置5,6,。。9),其他所有控件的tag均为0 用下面循环就可以了: for i:=0 to componentcount-1 do begin if components[i].tag > 0 then Tedit(components[i]).Enabled:=false; end;
var tmp:TEdit;i:integer; begin For i:=5 to 9 do begin tmp:=Form1.FindChildControl(Format('Edit%d',[i])) as TEdit; If Assigned(tmp) then tmp.Enabled:=false; end; end;我这样写就没有必要设置Tag属性。不过前提是Edit的Name的格式为“Edit”跟一个数字。而且Edit的Parent为Form1.如果是在Panel或其他容器中,那么你必须要修改我的代码中的 Form1
用下面循环就可以了:
for i:=0 to componentcount-1 do
begin
if components[i].tag > 0 then
Tedit(components[i]).Enabled:=false;
end;
begin
For i:=5 to 9 do
begin
tmp:=Form1.FindChildControl(Format('Edit%d',[i])) as TEdit;
If Assigned(tmp) then tmp.Enabled:=false;
end;
end;我这样写就没有必要设置Tag属性。不过前提是Edit的Name的格式为“Edit”跟一个数字。而且Edit的Parent为Form1.如果是在Panel或其他容器中,那么你必须要修改我的代码中的 Form1