men*_*raz 3 delphi rtti delphi-xe
事实:
将Delphi XE2中引入的Rtti.TVirtualInterface成功引入以前的Delphi版本的成功独立工作分别由
Delphi.Mocks.VirtualInterface单位(德尔福模拟)DSharp.Core.VirtualInterface.pas单位Stefan Glienke (DSharp)发现:
题:
是否有人希望有一天能够在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);
Run Code Online (Sandbox Code Playgroud)