I’m writing a control that should be able to display any list of data. What I wanted to do, was to mimic the for-in construct in that I check for a public GetEnumerator function that contain a Current property and a MoveNext method.
I’ve determined the following:
- I can check the existance of a method by simply calling MethodAddress on my object. If I get the address, the method exists.
- I can use RTTI to check the return type of the method.
- I can use RTTI to check for the property and to read it.
In-between though, I am missing little bits of info:
- How do I call the method, given its address? Do I just write a definition (like I would for imports), cast the address and call it?
- Checking the return type of the method requires calling GetTypeData with its PTypeInfo. I get the PTypeInfo by calling TypeInfo on a type. So how do I get a PTypeInfo for a given method, given only its address?
So what you’re trying to do may not be possible under the current RTTI model. But Delphi 2010 is supposed to have an expanded RTTI system that will enable you to do stuff like that a lot more easily, and it’s due out RSN. (There used to be a release countdown on Embarcadero’s site that was counting down towards midnight tonight. They’ve taken it down, though, so I’m not sure if that’s still the official release date or not.)