我在 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;
如何通过名称找到 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;
关于delphi - 在 Delphi 7 中查找 TObject 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30189196/