在 Delphi 中找到 属性 作为 TObject 7

Find property as TObject in Delphi 7

我在 Delphi 中有两种类型的 类 7:

  TPhone = Class(TPersistent)
  private
    FNumber: string;
  published
    property Number: string read FNumber write FNumber;
  end;

  TPerson = class(TPersistent)
  private
    FFirstName: string;
    FPhone: TPhone;
  public
    constructor Create;
  published
    property FirstName: string40 read FFirstName write FFirstName;
    property Phone: TPhone read FPhone write FPhone;
  end;

如何通过名称和 return 在 TPerson 中找到 Phone 属性它作为 TObject ?

也许是这样的:

  function FindPropByName(AObject: TObject; APropName: string): TObject;

注意Phone是子类,没有原始类型

谢谢

例如这样:

uses
  TypInfo;

var
  Phone: TPhone;
  Person: TPerson;
begin
  ...
  if PropIsType(Person, 'Phone', tkClass) then
    Phone := GetObjectProp(Person, 'Phone') as TPhone;
  ...
end;