PDA

Click to See Complete Forum and Search --> : How can different forms use the same instance of a DLL's class?


saltrange
Mar 24th, 2002, 08:39 AM
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

Edneeis
Mar 24th, 2002, 02:47 PM
Just declare it in a standard module instead like this:

'in a module
Public DBMOD as New DatabaseModule.DBCLASS

saltrange
Mar 24th, 2002, 04:26 PM
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?

Edneeis
Mar 24th, 2002, 04:43 PM
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.

swb76
Apr 13th, 2002, 10:15 PM
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..

wolfofthenorth
Apr 18th, 2002, 10:59 PM
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

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