Bilbo_Baggins2
asked on
Object Instancing...
I'm wanting to write an object that behaves like MS Outlook in that when I go to get a refrence to it, if it's already running it will return the running instance. Is this possible in VB? Would or Could I do this as an ActiveX Exe project?
Dim MyObject as MyObject
Set MyObject = new MyObject
'if the object is already running, I want the currently running instance. So, theoretically I might have several refrences to it.
Any Ideas?
Dim MyObject as MyObject
Set MyObject = new MyObject
'if the object is already running, I want the currently running instance. So, theoretically I might have several refrences to it.
Any Ideas?
ASKER
I wrote a test program... I have one property that's a string. I want to set the property in the first instance then see that string when I read the property in each new Standard EXE instance I start. The test below doesn't work right. It's starting a new instance of clsTest each time I spawn it in the standard EXE. How do I get it to return the instance of the already running class?
The ActiveX Exe project is named clsTest and has the following code:
'''''''''''''''''''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''' ''
Private sName As String
Public Property Get NameOfInstance() As Variant
NameOfInstance = sName
End Property
Public Property Let NameOfInstance(ByVal vNewValue As Variant)
sName = vNewValue
End Property
'''''''''''''''''''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''' ''
The Standard Exe project has the following code:
'''''''''''''''''''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''' ''
Dim oTest As clsTest.clsTesting
Private Sub Command1_Click()
oTest.NameOfInstance = "Jeff"
End Sub
Private Sub Command2_Click()
Label1 = oTest.NameOfInstance
End Sub
'also tried createobject
Private Sub Form_Load()
Set oTest = New clsTest.clsTesting
End Sub
'''''''''''''''''''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''' ''
The ActiveX Exe project is named clsTest and has the following code:
''''''''''''''''''''''''''
Private sName As String
Public Property Get NameOfInstance() As Variant
NameOfInstance = sName
End Property
Public Property Let NameOfInstance(ByVal vNewValue As Variant)
sName = vNewValue
End Property
''''''''''''''''''''''''''
The Standard Exe project has the following code:
''''''''''''''''''''''''''
Dim oTest As clsTest.clsTesting
Private Sub Command1_Click()
oTest.NameOfInstance = "Jeff"
End Sub
Private Sub Command2_Click()
Label1 = oTest.NameOfInstance
End Sub
'also tried createobject
Private Sub Form_Load()
Set oTest = New clsTest.clsTesting
End Sub
''''''''''''''''''''''''''
Bilbo_Baggins2:
Is the ActiveX Exe program running in the background?
Dabas
Is the ActiveX Exe program running in the background?
Dabas
ASKER
>Is the ActiveX Exe program running in the background?
Yes, it's running in the background. When the first Standard exe starts it starts the ActiveX Exe if it isn't running yet.
Although the code above will start the ActiveX Exe.
Yes, it's running in the background. When the first Standard exe starts it starts the ActiveX Exe if it isn't running yet.
Although the code above will start the ActiveX Exe.
Bilbo_Baggins2:
What does the instancing property for the project show?
Dabas
What does the instancing property for the project show?
Dabas
ASKER
5 - MultiUse
Bilbo_Baggins2:
Try to change to GlobalSingleUse
IF that fails, then try one of the other settings
Dabas
Try to change to GlobalSingleUse
IF that fails, then try one of the other settings
Dabas
ASKER
that doesn't seem to work either. It still seems to be creating each new one as a new instance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Bilbo_Baggins2:
I leave you in Azra's very capable hands!
Dabas
I leave you in Azra's very capable hands!
Dabas
ASKER
Thanks Azra. That's exactly what I needed.
And thanks to you, Dabas. I appreciate the effort!
And thanks to you, Dabas. I appreciate the effort!
> Would or Could I do this as an ActiveX Exe project?
Yes
Dabas