Results 1 to 10 of 10

Thread: CreateObject with events

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662
    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.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662
    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.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662
    Can it be done?

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    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.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662
    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)

  8. #8
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    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

    Code:
    Set x.Parent = Me
    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.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662
    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.

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662
    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
  •  



Click Here to Expand Forum to Full Width