【发布时间】:2014-09-07 06:14:48
【问题描述】:
此代码不允许:
class constructor TOmniMultiPipelineStage.Create;
var
RTTIType: TRttiType;
begin
RTTIType:= TRttiContext.GetType(self);
end;
[dcc32 错误] OtlParallel.pas(5040): E2003 Undeclared identifier: 'self'
该变体也是不允许的:
class constructor TOmniMultiPipelineStage.Create;
var
RTTIType: TRttiType;
begin
//Not really what I want because I want the actual type of the class
//Not a fixed ancestor type
RTTIType:= TRttiContext.GetType(TOmniMultiPipelineStage);
end;
[dcc32 Error] OtlParallel.pas(5039): E2076 这种形式的方法调用只允许用于类方法或构造函数
如何在类构造函数中获取类的 RTTI 信息?
自我注意:循环遍历一个类的所有后代:Delphi: At runtime find classes that descend from a given base class?
【问题讨论】:
-
带有类前缀的方法(和ctors)是类成员;它们没有对对象的引用,因此没有定义“自我”。
-
@David 不是这样。类方法有一个 Self。它是元类。静态类成员没有 Self。碰巧的是,类构造函数是静态的,即使它们没有 static 关键字。
-
@david 详情:docwiki.embarcadero.com/RADStudio/en/…
标签: delphi reflection rtti