Delphi Classes-FindComponent 通过文本字符串名称,寻找组件(控件)

Delphi Classes-FindComponent 通过文本字符串名称,寻找组件(控件)

引用单元:Classes

函数原型:

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;

 

Delphi 使用示例:

var 
  sLabel: TComponent;
begin
  sLabel:= FindComponent("Label1");
  If sLabel is TLabel then
    TLabel (sLabel ).Caption:=' Delphi';
end;

  

 

 

创建时间:2020.05.27  更新时间:

 

posted on 2020-05-27 11:12  滔Roy  阅读(1446)  评论(0)    收藏  举报

导航