ic FInstance: TObject; end; //-----------------------------------------Borland.Delphi.System.pas-- 所有的元类如TDemo.@MetaTDemo类,都是继承自_TClass类,并使用类似TClassHelperBase的实现。 如TDemo.@MetaTDemo类就是以类似这样的伪代码定义的,只不过FInstance是静态成员变量
TDemo = class(TObject) public @MetaTDemo = class(_TClass) public FInstance: TObject; // static
class constructor StaticCreate; constructor Create;
... end;
class constructor TDemo.@MetaTDemo.StaticCreate; begin FInstance := @MetaTDemo.Create; // normal constructor end;
constructor TDemo.@MetaTDemo.Create; begin inherited;
inherited FInstanceType := token of HelloWorld.TDemo; end;
在@MetaTDemo的静态构造函数中,将@MetaTDemo.FInstance初始化为自身的实例; 在@MetaTDemo的构造函数中,将其表示类的Token放入_TClass.FInstanceType中, 我们后面分析Borland.Delphi.System单元时再详细解释。
这一小节我们大概了解了Delphi.NET是如何为原有Delphi类在源代码一级提供兼容性的, 分析了class helper和元类 MetaClass的实现原理。下一节我们将开始分析Delphi.NET的 核心单元Borland.Delphi.System,了解Delphi的基于TObject的单根结构是如何映射到 CLR的FCL基于System.Object的单根结构上,并看看几个我们熟悉的TObject方法的实现, 了解Delphi和Delphi.NET在类的内存布局上的不同。
上一页 [1] [2] |