RTTI question

RTTI question

How to use rtti to check if a class field is an interface of a specific type?

rFld : TRttiField;

result := (rFld.FieldType is TRttiInterfaceType) and (?? is IMyInterface);

Comments

  1. You will need a GUID on your interface.

    Working from memory, it might be something on the lines of:

    TRttiInterfaceType(rFld.FieldType).Guid.Equals(GetTypeData(TypeInfo(IMyInterface))^.Guid);

    ReplyDelete
  2. you can even do:
    If RTTIInterface.Guid = IMyInterface then

    Interfaces allow implicit cast to TGuid :)

    ReplyDelete

Post a Comment