开发者

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 开发者_Go百科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).


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.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜