Hal*_*oDu 1 delphi attributes visibility rtti delphi-xe
在我的应用程序中,我实质上有以下类
TCategory = class(TAbstractionTreeItem)
private
fName: String;
fParent: Integer;
fComment: String;
public
procedure Default; override;
protected
procedure Validate(Validation: TValidation); override;
published
[AbstractionField]
property Name: string read fName write fName;
[AbstractionField]
property Parent: Integer read fParent write fParent;
[AbstractionField]
property Comment: String read fComment write fComment;
end;
Run Code Online (Sandbox Code Playgroud)
当我现在尝试通过Delphi XE中的高级RTTI获取有关信息时,我获取已发布属性的可见性信息,结果告诉我它们只是公开的,并且我添加的属性根本没有显示.
那里发生了什么?我已经尝试验证它是我尝试分析的正确类,并且在发生更改时重新编译属于它的单元.这似乎不是问题.
为了使您的代码能够编译,我更改了以下内容:
AbstractionField = class(TCustomAttribute)
end;
TCategory = class(TObject)
private
fName: String;
fParent: Integer;
fComment: String;
public
procedure Default;
protected
procedure Validate(Validation: Integer);
published
[AbstractionField]
property Name: string read fName write fName;
[AbstractionField]
property Parent: Integer read fParent write fParent;
[AbstractionField]
property Comment: String read fComment write fComment;
end;
Run Code Online (Sandbox Code Playgroud)
然后我编写了以下代码来查询属性的可见性:
var
C : TRttiContext;
T : TRttiType;
P : TRttiProperty;
begin
T := C.GetType(TCategory.ClassInfo);
for P in T.GetProperties do
begin
Memo1.Lines.Add(P.Name + ' ' +
GetEnumName(TypeInfo(TMemberVisibility),ord(P.Visibility)) );
end;
end;
Run Code Online (Sandbox Code Playgroud)
我的结果(按预期):
Name mvPublished
Parent mvPublished
Comment mvPublished
Run Code Online (Sandbox Code Playgroud)
我也在使用Delphi XE,你必须提供更多代码,以便我们可以复制问题.
另外,请确保检查以下警告:[DCC警告] UnitName.pas(LineNum):W1025不支持的语言功能:'自定义属性'
这是识别属性是否输入错误且编译器无法找到的唯一方法.
归档时间: |
|
查看次数: |
1345 次 |
最近记录: |