Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: Still in the dark... Static or Singleton objects ?


Message #1 by "Nikolai Devereaux" <yomama@u...> on Tue, 14 Aug 2001 15:10:26 -0700
I have a class that is shared between all other classes in my project. 
I defined a "Parent" property in all classes that using this class and set
Parent to this common object.


-----Original Message-----
From: Nikolai Devereaux [mailto:yomama@u...]
Sent: Wednesday, August 15, 2001 5:54 PM
To: professional vb
Subject: [pro_vb] RE: Still in the dark... Static or Singleton objects ?


Problem is that this property isn't available for me.  I've defined a class
module within a project, and need to ensure that each form in the project
has a private member variable of that object type.

I've decided that the easiest way was just to have one instance of it
defined in some .bas module, and have each form

Dim WithEvents m_nik as NiksObject
Set m_nik = MyModule.theOneNiksObject

> -----Original Message-----
> From: Pardee, Roy E [mailto:roy.e.pardee@l...]
> Sent: Wednesday, August 15, 2001 7:39 AM
> To: professional vb
> Subject: [pro_vb] RE: Still in the dark... Static or Singleton objects ?
>
>
> Ah, now I think I see what you're asking--I didn't know the
> terminology you
> were using.
>
> I believe the Instancing property of the NiksObject class is what you need
> to set--most likely to MultiUse.  Have a look at the help file and see if
> that's it.
>
> Cheers,
>
> -Roy
>
> -----Original Message-----
> From: Nikolai Devereaux [mailto:yomama@u...]
> Sent: Tuesday, August 14, 2001 3:10 PM
> To: professional vb
> Subject: [pro_vb] Still in the dark... Static or Singleton objects ?
>
>
>
> How do you create a static object?  I've written a class module,
> but need to
> ensure that only one instance of that object is shared among all the other
> objects/forms that use it.
>
> Right now, I'm doing this:
>
> My object name is "NiksObject" and contains events.
>
> In a .bas Module called "Utilities" set up a public global instance of it:
>     Public someObj As New NiksObject
>
>
> In each Form that uses it:
>     Private WithEvents objNiks as NiksObject
>     Private Sub Form_Load()
>         set objNiks = Utilities.someObj
>     End Sub
>
>     Private Sub objNiks_Event1()
>        ...
>     End Sub
>     ...
>
> Is this the only way?  It seems really round about than the traditional
> static object approached used in Java, C++, etc...

  Return to Index