Identifying classes/components that implements certain interfaces 
Author Message
 Identifying classes/components that implements certain interfaces

If I have different classes implementing an interface, how do I identify
all those classes at run time....?

Thanks!

Helge



Sat, 22 Jul 2000 03:00:00 GMT  
 Identifying classes/components that implements certain interfaces

Hello Helge,

You do it the same way in any COM enabled language.  If you have an object
(i.e. an Interface pointer), you run QueryInterface using that pointer on
the object to see if its supports the interface you need.

This is done in VB by attempting to create an object of the type you need
from the object that is the type you have:

Public Sub DoStuff(IOldInterface As MyServer.OldInterface)
    On Error Goto Failed_Interface_Fallover
    Dim INewInterface As MyServer.NewInterface

    ' try the new interface first, fall back to the
    ' old interface is the new one is not available
    Set INewInterface = MyServer.OldInterface

    ' do stuff using the new interface if this line completes
    Exit Sub

    Failed_Interface_Fallover:
        Set IOldInterface = New MyServer.OldInterface

        ' do stuff using older interface
        Exit Sub

Rather than using an error trap proceedure, you might want to turn off error
trapping (on error goto 0) and check the Err object after the call to see if
it errored with the "Can't create object" error, and act accordingly.

If you had a bunch of objects, like a collection, and you wanted to create
another list or collection that contained only objects that contained a
particular interface, you could use a function like this one to filter the
collection.

I hope this helps,

Larry R. Tubbs Jr., MCPS, MCSD
Silverleaf Resorts Inc, NYSE: SVR

Quote:

>If I have different classes implementing an interface, how do I identify
>all those classes at run time....?

>Thanks!

>Helge



Sat, 22 Jul 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Implementing IUnknown interface in Access 2000 class

2. Implementing the IEnumerator interface in my custom class

3. Which classes implement an interface?

4. Need help Implement a class interface.

5. Implementing public interface of another class

6. Problems calling VB Components from ASP using Interfaces Classes

7. IMPLEMENTING AN INTERFACE MADE FROM ANOTHER INTERFACE

8. Implementing an interface made from another interface

9. IMPLEMENTING AN INTERFACE MADE FROM ANOTHER INTERFACE

10. Implementing an interface made from another interface

11. NEWBIE: Interface of MTS Component - How do I generate an the Interface Information

12. Best approach to implement security and identify users.

 

 
Powered by phpBB® Forum Software