gpt4 book ai didi

delphi - RTTI.TRttiIndexedProperty 向后移植到 Delphi XE

转载 作者:行者123 更新时间:2023-12-03 15:48:48 24 4
gpt4 key购买 nike

事实:

分别成功地将Delphi XE2中引入的Rtti.TVirtualInterface引入到以前的Delphi版本中

  • Vincent Parrett,位于 Delphi.Mocks.VirtualInterface 单元 ( Delphi Mocks )
  • Stefan Glienke 在 DSharp.Core.VirtualInterface.pas 单元 ( DSharp )
<小时/>

调查结果:

  • TRttiIndexedProperty 派生自 TRttiMember。
  • TRttiType 和 TRttiInstanceType 依赖于 TRttiIndexedProperty。
  • Rtti.pas 依赖于 TypInfo.pas,其中还引入了一些重大更改。
<小时/>

问题:

是否希望有一天有人能够在 Delphi XE 上引入 TRttiIndexedProperty?

最佳答案

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);

关于delphi - RTTI.TRttiIndexedProperty 向后移植到 Delphi XE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9690523/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com