-
I need to create an object at runtime from a user specified class. The object is using a standard interface (infact I created a class (in project1) called "iExternal" that has this interface). The external object happens to have a couple of events that I need to handle. If I use
Code:
Dim a As iExternal
Set a = CreateObject("project2.class1")
then I get e type mismatch. I really need to handle the events in project2.class1. Is there a way to do this? The reason I tried this is another vb resource that talked about polymorphism said this could be done. I really need help on this one. My project is scrapped without a workaround.
BTW, since this is to allow for third-party plugins, I can't use any design-time references to the created object.
-
How about:
Code:
Dim WithEvents x as iExternal
Private Sub Form_Load()
Set x = CreateObject("Project1.Class1")
End Sub
Would this work?
-
still causes the type mismatch error. i forgot the withevents in the code in my first post. but i really need to get rid of the type mismatch error.
-
-
I'm not sure. I'll have to do some checking...
-
VB Interfaces can have Methods and Property procedures that the class that implements the interface must implement. But as far as I know interface classes can't have events. Or rather they can't be inheritad by the other class.
-
I just came up with "Plan B": is there a way vb can execute a procedure if I know it's address (the one obtained from AddressOf)
-
you can't run a procedure from it's address, Try this.
Have a Parent property of the iExteranl class as object, then pass the parent into the instance of the control with
then you can call public methods of the parent object from inside the child, if you have set names for these functions then you can use them like events, make sure you have error handling inside iExternal in case the procedures aren't there.
Just out of intrest, why can't you just use
Code:
Set x = New iExternal
rather than use createobject.
-
iExternal is the interface template for the dll. It has a bunch of procedure definitions and events in it, but no code. I'll try that. I really hope it works.
-
Sam, your code gave me an idea. Instead of passing a container form, I just passed a special class (from project1) that has the methods i need. Seems to work great. Thank you.