2012-03-13 148 views
3

事实:反向移植RTTI.TRttiIndexedProperty的德尔福XE

全成独立的努力,使Rtti.TVirtualInterface在Delphi XE2引入前德尔福版本分别由

  • 文森特Parrett在做Delphi.Mocks.VirtualInterface单位(Delphi Mocks
  • Stefan Glienke DSharp.Core.VirtualInterface.pas单位(DSharp

发现:

  • TRttiIndexedProperty从TRttiMember的。
  • TRttiType和TRttiInstanceType取决于TRttiIndexedProperty。
  • Rtti.pas依赖于TypInfo.pas,其中还引入了一些突破性更改。

问:

是否有一个希望,有一天,有人将有可能带来TRttiIndexedProperty德尔福XE?

+2

这个问题与洁净室实现有什么关系? – 2012-03-13 20:17:56

+0

@Rob现在它是一个答案。 – 2012-03-13 20:52:34

+0

@Rob Kennedy:标题改为。 – menjaraz 2012-03-14 04:20:34

回答

6

TRttiIndexedProperty无法被移植到旧的Delphi版本,因为它取决于编译器为索引属性写出RTTI数据,只有Delphi XE2的编译器所做的工作。你无法阅读那些不存在的东西。

您拥有的唯一可能性就是手工编写这些数据。所以你必须编写一个解析器来运行你的所有代码,并为所有索引属性生成必要的类型信息。因为你的解析器不是编译器,所以你也必须编写一些帮助函数来编写和读取索引属性。 输出可能是这样的:

TMyClass = class 
private 
    ... 
public 
    property MyArray[Index: Integer]: TMyObject read GetMyArray write SetMyArray; 

    // autogenerated code 
    class procedure RegisterIndexedPropertyInfos(Registry: TMyRttiIndexedPropertyRegistry); static; 
end; 

// autogenerated code 
class procedure TMyClass.RegisterIndexedPropertyInfos(Registry: TMyRttiIndexedPropertyRegistry): TMyRttiIndexedProperty; 
begin 
    Registry.Register('MyArray', [TMyRttiIndex.Create('Index', TypeInfo(Integer))], TypeInfo(TMyObject), @TMyClass.GetMyArray, @TMyClass.SetMyArray); 
end; 

// When using RichRTTI you can omit this line and use the the RttiContext to find RegisterIndexedPropertyInfos 
RegisterIndexedPropertyClass(TMyClass, @TMyClass.RegisterIndexedPropertyInfos);