略作改进:
with Form do
for i:=0 to ComponentCount-1 do
begin
if Components[i] is TEdit then
IF Components[i].NAME='EDIT1' THEN
{DO SOMETHING}
ELSE IF Components[i].NAME='EDIT2' THEN
....
end;
反对for +Case 的嵌套,这样的代码效率和可读性并不强。但tag的使用是一个很好的方向。
大致上while not findcomponent do
begin
find your edit component having your tag with function findcomponent(),
do smoething.
end
with Form do
for i:=0 to ComponentCount-1 do
begin
if Components[i] is TEdit then
case (Components[i] as TEdit ).Tag of
{Your stuff code}
1: ;//
2: ;//
else
//
end;
end;