Results 1 to 5 of 5

Thread: Any way to have a form implement and interface?

  1. #1

    Thread Starter
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Question Any way to have a form implement and interface?

    I have a handful of MDI forms with the same set of public functions. Is there any way to have a form implement an interface and then test for that interface, ie. "Implements iCustom". I've played around with it briefly and can get private interfaces to attach themselves, but the idea of an interface with all private members seems silly. I suspect this is out of VB6's league, but thought I'd make sure.

  2. #2

  3. #3

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Any way to have a form implement and interface?

    Hmmm. You can create an interface class containing the function stubs. Each MDI child will implement that interface. Then to call a specific MDI child's interface, the logic would look something like...
    Code:
    ' iCustom interface
    Option Explicit
    Public Function ObjectPointer() As Long
       ' stub
    End Function
    
    ' each child form
    Implements iCustom
    Private Function iCustom_ObjectPointer() As Long
        iCustom_ObjectPointer = ObjPtr(Me)
    End Function
    
    ' the MDI parent
    Dim theInterface As iCustom
    Set theInterface = Me.ActiveForm
    Debug.Print theInterface.ObjectPointer, ObjPtr(Me.ActiveForm)
    Don't kow if you already had this? If not, then is this what you are looking for?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Re: Any way to have a form implement and interface?

    Quote Originally Posted by MartinLiss
    Leaving aside how to do it, what is it you are trying to accomplish?
    I have several different types of displays in ListViews, and need to update all of them in a loop. Right now, I check the TypeName of the forms in a loop through the Forms collection. Problem is, as I add new forms that need to update, checking all of the TypeNames is becoming unwieldly. I also use some public functions to handle things like right-click popup menus, custom sort types, etc. where I expose the ListView through a custom property (that way I don't have to name them all the same thing). This would be a lot easier to maintain if I had a custom interface to use.

    @LaVolpe: That's an interesting idea, and one that I hadn't thought of. I'll have to play around with it a little bit.

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