|
-
Jan 17th, 2018, 05:28 PM
#1
Re: Question about classes in VB6
 Originally Posted by Elroy
@couttsj & Eduardo: Variables are common to all Aliases of a class, but they're not at all common to all Instances of a class. Those two concepts are entirely different. Couttsj, I suspect you were aliasing your class rather than creating different instances when you were doing your testing.
Sorry, but I don't understand the concept of aliasing. Is this aliasing?
Code:
ReDim mServer(MaxClients)
For lNum = 0 To MaxClients
Set mServer(lNum).Callback(lNum) = Me
mServer(lNum).IPvFlg = 4
Next
And if so, how would it be done differently?
J.A. Coutts
-
Jan 17th, 2018, 05:44 PM
#2
Re: Question about classes in VB6
 Originally Posted by couttsj
Sorry, but I don't understand the concept of aliasing. Is this aliasing?
Yes
 Originally Posted by couttsj
And if so, how would it be done differently?
Code:
ReDim mServer(MaxClients)
For lNum = 0 To MaxClients
Set mServer(lNum).Callback(lNum) = New Class1 ' New Instance with separate local variables.
mServer(lNum).IPvFlg = 4
Next
-
Jan 17th, 2018, 05:57 PM
#3
Re: Question about classes in VB6
 Originally Posted by couttsj
Sorry, but I don't understand the concept of aliasing. Is this aliasing?
Code:
ReDim mServer(MaxClients)
For lNum = 0 To MaxClients
Set mServer(lNum).Callback(lNum) = Me
mServer(lNum).IPvFlg = 4
Next
The above would only work, in case you have defined the mServer()-Array with the New-keyword.
If that is the case, then no - this is not "aliasing" (which is just another word for: "two different Variables point to the same thing").
What I find surprising is, that not many devs have done a few tests themselves (a decade or two ago),
by using a simple Class1 - and a few Debug-Statements in its Class-Init and Terminate-Events.
Because doing so would shed a lot of light on "when things start to come online" and "when things are going to die"... 
Here's some code, which shows what's going on behind the scenes of your example:
Class1:
Code:
Option Explicit
Private Sub Class_Initialize()
Debug.Print "Class1 instantiated: " & ObjPtr(Me)
End Sub
Public Property Get SomeProp() As String
SomeProp = "Class1 PropAccess: " & ObjPtr(Me)
End Property
Private Sub Class_Terminate()
Debug.Print "Class1 terminated: " & ObjPtr(Me)
End Sub
Form-Code:
Code:
Option Explicit
Private mServer() As New Class1, lNum As Long
Private Sub Form_Click()
ReDim mServer(2) 'a Redim like that (without Preserve) destroys any potentially existing intances in the Array
For lNum = 0 To UBound(mServer)
Debug.Print mServer(lNum).SomeProp
Next
End Sub
Please click repeatedly on the Form - whilst having a breakpoint at the first statement in Form_Click.
Then step through it and watch the Debug-Window (there's only 3 entries in the Array, won't take long).
HTH
Olaf
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|