|
-
Aug 21st, 2000, 04:47 PM
#1
Thread Starter
Fanatic Member
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.
-
Aug 21st, 2000, 04:51 PM
#2
Monday Morning Lunatic
How about:
Code:
Dim WithEvents x as iExternal
Private Sub Form_Load()
Set x = CreateObject("Project1.Class1")
End Sub
Would this work?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 21st, 2000, 05:14 PM
#3
Thread Starter
Fanatic Member
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.
-
Aug 21st, 2000, 06:14 PM
#4
Thread Starter
Fanatic Member
-
Aug 21st, 2000, 06:15 PM
#5
Monday Morning Lunatic
I'm not sure. I'll have to do some checking...
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 21st, 2000, 07:44 PM
#6
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.
-
Aug 21st, 2000, 07:58 PM
#7
Thread Starter
Fanatic Member
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)
-
Aug 21st, 2000, 08:39 PM
#8
Frenzied Member
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.
-
Aug 21st, 2000, 09:05 PM
#9
Thread Starter
Fanatic Member
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.
-
Aug 21st, 2000, 10:12 PM
#10
Thread Starter
Fanatic Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|