[RESOLVED] VB 6.0 Object Reference
Hello all, this is my first post on CodeGuru.
I am currently developing an ActiveX exe using VB 6.0. My plan calls for a private class (clsJournalBase) to be delcared and instanced once through sub Main() when the first exportable object is created.
I have two classes (clsJournal and clsJournalMaster both GlobalMultiUse) that can be exported through this exe; I am trying to get each object exported to create a reference to the single instance of clsJournalBase in the main module in order to have the exported objects react to events raised from clsJournalBase.
I know I cannot use the GetObject() function since I have created these classes in VB; and when I try to create my own function to pass the reference (written as a public function in main module), it creates a new instance in the two exported classes.
Is there a way to pass a reference back with out using GetObject()?
Any help would be appreciated. If some one has already posted a similar situation, please let me know or link to it.
Thank you in advance.
Re: VB 6.0 Object Reference
Or is there another way to access the messages from clsJournalBase in my two exportable classes that will allow me to avoid setting up a property in each class as type clsJournalBase?
Finally, the ActiveX exe is going to be stored and run on a network server (Windows 2003 Small Business) while the client apps are run on client machines (Win XP SP2); I have tested event firing across the network and it has performed fine, I am just unsure if this would add any more complication to the structuring of my classes.
Here is a simplified version of the code.
clsJournalBase's code is really not important to this problem. Just keep in mind that the class contains events. Also keep in mind that the start up object is Sub Main().
Main Module
Code:
Private JournalBase as clsJournalBase
Public Sub Main()
set JournalBase = New clsJournalBase
End Sub
Public Function GetJournalBase() as clsJournalBase
set GetJournalBase = JournalBase
End Function
clsJournalMaster and clsJournal both have the following constructs.
Code:
Private WithEvents m_objJournalBase as clsJournalBase
Private Sub Class_Initialize()
set m_objJournalBase = MainModule.GetJournalBase()
End Sub
'Event Handlers for events raised in clsJournalBase.
Of course each of the classes has more code that does the actual processing for its tasks; this is the relavant code for how I reference the classes.
Re: VB 6.0 Object Reference
Okay, apparently I am trying to create a Singleton Object. After doing some research, I have ordered a book "Advanced Visual Basic 6" and will post if the solutions work.
If anyone has any opinions about singletons, I'd love to hear them.
Re: VB 6.0 Object Reference
Why? I've never seen a purpose for them in a language that doesn't support inheritance. They might have a purpose in .NET, but VB6?
Re: VB 6.0 Object Reference
Ever think of searching for it? I found the article that i was thinking of in a few seconds.
http://www.vbforums.com/showthread.php?t=310205
Re: VB 6.0 Object Reference
The base class needs to modify system wide globally unique data. If there is a better way to do that, then I would love to hear it. This has been frustrating beyond all end.
Re: VB 6.0 Object Reference
Sorry dglienna, I just found out what the technique is called today. Had I known I would not have posted a thread; and since the thread was already started, I thought I would mention that I found the book.