Not a major problem, but given that xProp is a TRttiProperty instance is there a better way to get the ClassType of a property that is tkClass?

Not a major problem, but given that xProp is a TRttiProperty instance is there a better way to get the ClassType of a property that is tkClass?

x := GetTypeData(xProp.PropertyType.Handle)^.ClassType;

Comments

  1. Just hoping the info actually was exposed somewhere directly from TRttiProperty or one of its object properties.

    If I cant find shorter/simpler its not critical. Just seeing if I missed something, or if they left this out. There is one property that could help, but its a private property (yes, property) in the RTTI class and it basically does the same as above anyway.

    Without digging to confirm, it appears its falling back on the older RTTI structure without exposing it directly which is unusual considering everything else that extended RTTI exposes.

    Its just that kind of code that when stumbled upon in the future screams "Why the heck is it written that way???". Comments of course have been added to it...

    ReplyDelete
  2. All RTTI can be accessed with the pointer structures from TypInfo.pas (and digging through the binary yourself). Classes from Rtti.pas just use that and provide a nicer to use API plus dynamic invocation which requires alot of plumbing for parameter passing. So of course the TRttiSomething classes are eventually using the pointer structures like PPropInfo or PTypeInfo.

    ReplyDelete
  3. Yes of course. But still the same point. Am I missing something, or have they not exposed ClassType for properties of tkClass without having to go deep manually? Just about everything else is exposed, kind of expected this to be as well.

    ReplyDelete
  4. If that line were any longer it could be a Java class name! :-)

    ReplyDelete
  5. I normally break these up for easier debugging with block vars, and at least I could do that in Java. In Delphi I end up with a zillion names up top that I have to make long to avoid conflicts etc....

    ReplyDelete
  6. The System.Rtti way is this -

    x := xProp.PropertyType.AsInstance.MetaclassType;

    Been in since TRttiContext was first added, IIRC.

    ReplyDelete
  7. Chris Rolliston Perfect Chris. Thanks. I had actually used this elsewhere, don't know why I didnt match it up when I needed it here.

    ReplyDelete

Post a Comment