var _Label:TLabel; i:integer; begin For i:=1 to 4 do if FindComponent('Label'+inttostr(I)) <> nil then begin _Label:=FindComponent('Label'+inttostr(I))as TLabel; _Label.Text:=inttostr(i); end; end;
var i,c: integer; begin c:=1; for i := 0 to self.ComponentCount - 1 do begin if self.Components[i] is TLabel then (self.Components[i] as TLabel).Caption := inttostr(c); inc(c); end; end;
如果那4个TLabel的名字没带数字序列号的,可以这样:var i:integer; Labels: Array[0..3] of TLabel; begin Labels[0]:=startLbl;//相当于Label1 Labels[1]:=endLbl;//相当于Label2 Labels[2]:=connLbl;//相当于Label3 Labels[3]:=countLbl;//相当于Label4 for i:=0 to 3 do Labels[i].Caption:= inttostr(i); end;
_Label:TLabel;
i:integer;
begin
For i:=1 to 4 do
if FindComponent('Label'+inttostr(I)) <> nil then
begin
_Label:=FindComponent('Label'+inttostr(I))as TLabel;
_Label.Text:=inttostr(i);
end;
end;
i,c: integer;
begin
c:=1;
for i := 0 to self.ComponentCount - 1 do
begin
if self.Components[i] is TLabel then
(self.Components[i] as TLabel).Caption := inttostr(c);
inc(c);
end;
end;
Labels: Array[0..3] of TLabel;
begin
Labels[0]:=startLbl;//相当于Label1
Labels[1]:=endLbl;//相当于Label2
Labels[2]:=connLbl;//相当于Label3
Labels[3]:=countLbl;//相当于Label4
for i:=0 to 3 do Labels[i].Caption:= inttostr(i);
end;