for i := 7 to 8 do begin TLabel(FindComponent('Label'+ IntToStr(i))).Caption := IntToSt(i); end;
你可以把Label7——Label100做成数组,具体如下: var lst: TStrings; begin lst := TStringList.Create(nil); lst.AddObject('', Label7); lst.AddObject('', Label8); …… lst.AddOjbect('', Label100); lst.Free; end; 然后你就可以通过循环来实现: for i := 0 to lst.Count - 1 do begin TLabel(lst.Objects[i]).Caption := ' '; end;OK?
begin
TLabel(FindComponent('Label'+ IntToStr(i))).Caption := IntToSt(i);
end;
var lst: TStrings;
begin
lst := TStringList.Create(nil);
lst.AddObject('', Label7);
lst.AddObject('', Label8);
……
lst.AddOjbect('', Label100);
lst.Free;
end;
然后你就可以通过循环来实现:
for i := 0 to lst.Count - 1 do
begin
TLabel(lst.Objects[i]).Caption := ' ';
end;OK?