将RTTI.TRttiIndexedProperty移植到Delphi XE [英] Backport of RTTI.TRttiIndexedProperty to Delphi XE

查看:110
本文介绍了将RTTI.TRttiIndexedProperty移植到Delphi XE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

事实:

成功的独立努力将Delphi XE2中引入的 Rtti.TVirtualInterface 引入了先前的Delphi版本是分别由

Successfull independent efforts to bring Rtti.TVirtualInterface introduced in Delphi XE2 to prior Delphi versions were made respectively by


  • Vincent Parrett在 Delphi.Mocks.VirtualInterface 单元(< a href = https://github.com/VSoftTechnologies/Delphi-Mocks rel = nofollow> Delphi Mocks )

  • Stefan Glienke in DSharp.Core.VirtualInterface.pas 单元( DSharp

  • Vincent Parrett in Delphi.Mocks.VirtualInterface unit (Delphi Mocks)
  • Stefan Glienke in DSharp.Core.VirtualInterface.pas unit (DSharp)

发现:


  • TRttiIndexedProperty衍生自TRttiMember。

  • TRttiType和TRttiInstanceType取决于TRttiIndexedProperty。

  • Rtti .pas取决于TypInfo.pas,其中还引入了一些重大更改。

问题:

是否有希望有人可以将TRttiIndexedProperty带到Delphi XE上?

Is there a hope that one day someone will make it possible to bring TRttiIndexedProperty on Delphi XE ?

推荐答案

TRttiIndexedProperty不能反向移植到较早的Delphi版本,因为这取决于编译器为索引属性写出RTTI数据,只有Delphi XE2的编译器才能完成。您看不到其中不存在的内容。

TRttiIndexedProperty can't be back-ported to older Delphi versions because it depends on the compiler writing out RTTI data for indexed properties, what only Delphi XE2's compiler does. You can't read something that isn't there.

您唯一的可能是手工编写此数据。因此,您必须编写一个运行在所有代码上的解析器,并为所有索引属性生成必要的类型信息。而且由于解析器不是编译器,因此您还必须编写一些辅助函数来编写和读取索引属性。
输出可能是这样的:

The only possibility you have would be to write this data by hand. So you have to write a parser that runs over all your code and generates the necessary type information for all indexed properties. And because your parser isn't the compiler you would also have to write little helper functions that write and read the indexed-property. The output could be something like this:

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

这篇关于将RTTI.TRttiIndexedProperty移植到Delphi XE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆