Search code examples
delphidelphi-2010rtti

Trouble playing with indexed propertes via new RTTI [D2010]


  ShowMessage(TRttiContext.Create.GetType(TStringList)
    .GetProperty('Strings').ToString);

Above code fails as .GetProperty returns nil on properties like "Strings", "Objects", "Values" (ones with indexers). I assume this is a known limitation and the question is if there's any way to access those indexed properties (preferably without falling back to the old RTTI utils).


Solution

  • Indexed properties don't have RTTI, but the underlying fields do. So you can access TStringList.FList directly through RTTI. Be careful, though, as this involves raw pointers, and make sure you don't go beyond the Count property. You can do similar things with other classes.