Singletons

From HashVB
Revision as of 15:54, 15 January 2006 by 85.255.114.134 (Talk)

Jump to: navigation, search
float
 This article is based on Visual Basic 6. Find other Visual Basic 6 articles.

Singleton objects are useful for sharing data between multiple callers.

Single process

A singleton to be shared throughout a single project is easy.

Public Singleton As New SingletonObject

As long as this is in a module, this variable (a single instance of the object) will be accessible from the entire project. Ideally, you should remove the "New" and use this once on startup

Set Singleton = New SingletonObject

asain + gay + thumbs spy cam hunk hidden camera voyeur gay wrestling gay anal gay boy upskirt galleries sean cody voyeur sex gay teens hunks gay free project voyeur gay incest gay fucking free gay movie clips gay photography gay orgy spy sweeper free gay movies free voyeur web hunk totally spies porn gays spy cam gay rape hot hunks gay hentai gay porn free gay movie clips free project voyeur gay cum spy cameras hot hunks hot hunks hunks free gay movies gay hentai young teens flashing thongs gay anal sex voyeur photos hung hunks igor voyuerweb gay marriage gay gay fucking spy sweeper naked hunks free gay movies gay blowjobs voyeur sex gay marriage naked hunks free gay pics teen voyeur gay cartoons gay boys twink candid upskirt gay men gays gay photography voyeur upskirt gay boy gay blowjobs gay sex gay orgy gay spy gay cock voyeur sex gay hunks free voyeur free gay pics hunk free gay porn girls flashing hunk gay wrestling gay incest gay anal hunk spy twinks gay cartoons gay anal hot hunks gay boy voyeur beach gay cock totally spies hentai gay college girls flashing gay hunks gay fuck gay porn free gay porn naked hunks college girls flashing gay wrestling spycam gay marriage upskirt gay anal hot hunks gay wrestling hunks gay voyuerweb gay photography spy cameras gay cartoons spy twinks gay teens gay porn hidden cam gay photography gay hentai

Multiple processes

If you want to access a singleton object across multiple processes, you need to put in a bit more effort. As there can only be a single "owner", this will need to be a separate process (or ActiveX EXE) from all the callers that contains 3 important parts.

  • The singleton class
  • A public variable of the singleton class
  • A global class that allows access to the public variable

The variable is very much like the one used for the single process sample above as it is only directly accessed by (multiple instances of) the global class.

The global class only needs to contain a single function that will instantiate the singleton object if it hasn't been created already and then return it.

Public Function GetSingleton As SingletonObject
  If Singleton Is Nothing Then Set Singleton = New SingletonObject
  Set GetSingleton = Singleton
End Function

If any other caller then creates another instance of the global object and calls GetSingleton, it will return the already created object.

As soon as all references have been released or destroyed then it will cleanly shutdown.

Please note that this can't be done using COM DLLs as the "public" variables are private to each application.

Enjoy.