?
Solved

how can i enumerate the interfaces supported by an IDispatch?

Posted on 2004-10-06
4
Medium Priority
?
469 Views
Last Modified: 2010-04-05
it sure would be nice to be able to get an enumeration of all the interfaces supported by an IDispatch descendant.  any ideas?  i ask because i am not sure what type(s) are being returned.  i want to not need to know the GUID.

thanks!
mp
0
Comment
Question by:mikepj
  • 2
  • 2
4 Comments
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 500 total points
ID: 12244262
Interesting. I never knew this was possible to do. Actually, I don't think this is possible. Or if it's possible, it must have been implemented in some way by the development tool since there's no logic build-in into Delphi or COM to do this.
0
 
LVL 2

Author Comment

by:mikepj
ID: 12244392
i'm not saying it's possible but i am assuming it's possible.
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12247137
IDispatch is just an interface type that allows the use of dispatch interfaces. Basically, a dispatch interface is just a list of method indexes that also provide the correct syntax for the method. With the dispatch interface you can call the methods through the IDispatch interface of the object. This is done through the Invoke method of IDispatch that wants the dispatch ID of the method and some additional parameters and stuff.

IDispatch just lacks the information to provide information about the object itself. There are no methods in this interface that will help you enumerate all interfaces.

There is a way, though. This is a pure Delphi solution though, since other tools might have solved it differently. The TObject class has a class method called GetInterfaceTable that points to the table of interfaces that Delphi stores internally. Definitions:

type
  PInterfaceEntry = ^TInterfaceEntry;
  TInterfaceEntry = packed record
    IID: TGUID;
    VTable: Pointer;
    IOffset: Integer;
    ImplGetter: Integer;
  end;
  PInterfaceTable = ^TInterfaceTable;
  TInterfaceTable = packed record
    EntryCount: Integer;
    Entries: array[0..9999] of TInterfaceEntry;
  end;

If you have access to this interface table then you could enumerate all GUID's that this type supports. However, this only works for Delphi components and even worse, it's version-specific! It could even change when you patch your Delphi version. And you can only access it if you know the class type instead of the interface type.

So what if your IDispatch object was written in another language? Or in an unknown Delphi version? Well, then you just can't enumerate the interfaces, since all you have are the methods provided by the IDispatch interface.
0
 
LVL 2

Author Comment

by:mikepj
ID: 12253390
thank you for your response!

the trouble is that i get an IDispatch type returned and the only way i can find out anything is to try "as" for a "shopping list" of possible interfaces.

i'll leave this up for a bit and see if anyone comes up with anything more.

thanks,
mp
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question