for i:=1 to 10 do (FindComponent('Label'+IntToStr(i)) as TLabel).Caption:=IntToStr(i);
你上面的语句当然通不过了,每一个标签都是一个TLabel的实例对象,它并不是变量,而是一个对象! 你可以遍历所有窗体的Label嘛!用窗体的Components属性,得到所有窗体的控件,然后再判断当前得到的控件是不是TLable类!For count=o to Form1.Components.count-1 do begin if Form1.Components[count] is TLabel then
end;这个前提是窗体中每一个标签都是你要处理的标签呢!
呵呵,不过相信楼主自己心里明白到底可不可以!function TComponent.FindComponent(const AName: string): TComponent; var I: Integer; begin if (AName <> '') and (FComponents <> nil) then for I := 0 to FComponents.Count - 1 do begin Result := FComponents[I]; if SameText(Result.FName, AName) then Exit; end; Result := nil; end;
(FindComponent('Label'+IntToStr(i)) as TLabel).Caption:=IntToStr(i);
你可以遍历所有窗体的Label嘛!用窗体的Components属性,得到所有窗体的控件,然后再判断当前得到的控件是不是TLable类!For count=o to Form1.Components.count-1 do
begin
if Form1.Components[count] is TLabel then
end;这个前提是窗体中每一个标签都是你要处理的标签呢!
var
I: Integer;
begin
if (AName <> '') and (FComponents <> nil) then
for I := 0 to FComponents.Count - 1 do
begin
Result := FComponents[I];
if SameText(Result.FName, AName) then Exit;
end;
Result := nil;
end;