Results 1 to 6 of 6

Thread: How can different forms use the same instance of a DLL's class?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2001
    Posts
    30

    Talking How can different forms use the same instance of a DLL's class?

    Hi!

    I have a simple question.

    How do different forms in a Standard EXE project use the same reference to a DLL's class?

    How do I instantiate the object in one form,and use it in that form, as well as other forms in the Project?

    If I use:



    Dim DBMOD as DatabaseModule.DBCLASS

    Private sub Sub Form1_Load
    Set DBMOD = New DatabaseModule.DBCLASS

    End Sub


    How do I use the same object DBMOD in my other forms?? It should be instantiated in one form and then used again in that form as well as other forms(the same instance of it).


    Please help!!! thanks
    Last edited by saltrange; Mar 24th, 2002 at 09:48 AM.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Just declare it in a standard module instead like this:
    VB Code:
    1. 'in a module
    2. Public DBMOD as New DatabaseModule.DBCLASS

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2001
    Posts
    30
    Edneeis,

    that looks fine, but the problem is that you cannot Dim it WithEvents.

    In fact, I tried using WithEvents in the forms, but it doesnt accept it.

    Is there any solution?

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    If it didn't work in the forms then maybe it doesn't have events.

    Otherwise, if this is a dll you made, then to make a dll public across a project you can switch everything to a callback type situation, or you can (maybe although it'll be a lil bit of a pain) have each form keep its own private withevents version and then have one master public non event version, then when a form loads set the form one to the same instance as the public one. I don't know if you have one with events and one without, never tried it.

  5. #5
    swb76
    Guest
    there are two ways
    1) either at the top of form1 u delcare
    public DBMOD as DatabaseModule.DBCLASS and the form 2 would reference this object as form1.dbmod
    2) create a module and declare it globally..
    public dbmod as databasemodule.dbclass
    then all the forms could use this as dbmod..

  6. #6
    Addicted Member wolfofthenorth's Avatar
    Join Date
    Jan 2001
    Location
    Tatooine
    Posts
    169
    You could try this, too.


    In Form1--------------------------------------------------------------------

    private withevents DBMOD as DatabaseModule.DBCLASS

    Form1_load

    Set DBMOD = NEW DatabaseModule.DBCLASS
    Form2.SetRef DBMOD

    End Sub

    ----------------------------------------------------------------------------





    Then In Form2----------------------------------------------------------------

    private withevents m_DBMOD as DatabaseModule.DBCLASS

    Public Sub SetRef (DBMOD as DatabaseModule.DBCLASS)

    set m_DBMOD = DBMOD

    End Sub

    -------------------------------------------------------------------------
    That which does not kill us, only makes us stronger.

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