var
i :integer;
begin
for i := 0 to form1.component.count-1 do
if form1.components[i] is Tlabel then
showmessage(TLabel(form1.Components[i]).Caption);
end;
i :integer;
begin
for i := 0 to form1.component.count-1 do
if form1.components[i] is Tlabel then
showmessage(TLabel(form1.Components[i]).Caption);
end;
form1.component.count-1 ->form1.ComponentCount-1
begin
if FindComponents('Label'+Inttostr(i)) Is TLabel then
begin
TLabel(FindComponents('Label'+Inttostr(i))).Caption := 'aa';
end;
end;
begin
if FindComponents('Label'+Inttostr(i)) Is TLabel then
begin
TLabel(FindComponents('Label'+Inttostr(i))).Caption := 'aa';
end;
end;
经典
var
i:integer;
begin
for i:= 1 to 10 do
begin
if Form1.FindComponent('Label'+Inttostr(i)) Is TLabel then
begin
TLabel(Form1.FindComponent('Label'+Inttostr(i))).Caption := 'aa';
end;
end;
end;
MyLabel:array[1..10]of Tobject;
然后使用Tcomponent(Mylabel[i])循环即可!