2012-03-13 70 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);