views:

118

answers:

2
  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).

+1  A: 

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.

Mason Wheeler
+1  A: 

There are gaps in the RTTI. Indexed properties are one.

But when you don't get the property name, why you try to access them? ;-) When you know there is such a property you can try a cast instead.

You don't get RTTI for method parameters of the typ

procedure MyProc(const AParam: array of AType)

also.

Anybody knowing more elements were we can't get RTTI?

Heinz Z.