menjaraz
menjaraz

Reputation: 7575

Backport of RTTI.TRttiIndexedProperty to Delphi XE

Facts:

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


Findings:


Question:

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

Upvotes: 3

Views: 430

Answers (1)

Andreas Hausladen
Andreas Hausladen

Reputation: 8141

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

Upvotes: 6

Related Questions