With the new extended RTTI in Delphi 2010, can a Delphi application (at run time) build a list of all classes which implement a given interface?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Technically yes, so long as the interface has a GUID and the classes you care about are in the interface sections of units.
The RTTI unit does not (yet) have an API for describing all interfaces that a class implements, but the data is in the type info.
The GUID for an interface type can be gotten from this expression:
or:
The class of the instance type can then be checked using
TClass.GetInterfaceEntry(IID)– if it returns non-nil, the class implements the interface.All classes declared in interface sections of units can be retrieved via
TRttiContext.GetTypes.Writing the actual iteration and extraction code is left as an exercise for the reader.