View Single Post
 
Old 06-25-2014, 04:48 PM
whatsup whatsup is offline Windows 7 64bit Office 2010 32bit
Competent Performer
 
Join Date: May 2014
Posts: 137
whatsup will become famous soon enough
Default

Quote:
These are semantic representations of definitions of data structures, not objects. But, yep, that is what the Me statement is for. It refers to the particular instance of the object of type Class1
Yes you're right of course, I missed that one instead was trying to treat the class as any class else (UserForm, Chart-Sheet, ...).

Quote:
I'n not sure what VarPtr(Me) is though... I can't figure that on out and the contents of that location are zero. That one is making my head spin
Interesting observation, but probably related to what you said above. Still we can make it visible, what's going on:
Code:
Private Sub Test_Class()
Dim objcls1 As Class1
    
Set objcls1 = New Class1
lng_objPtr = ObjPtr(objcls1)
lng_varPtr = VarPtr(objcls1)
    
    pointerToSomething "objcls1", lng_varPtr, lng_objPtr, coBytes
'Since VarPtr(Me) obtained in the class shows Zero check again:
    pointerToSomething "objClass1", lng_varcls1, lng_objcls1, coBytes

 Set objcls1 = Nothing

 If objcls1 Is Nothing Then
    Debug.Print vbTab & "Object is set to nothing"
Else
    Debug.Print vbTab & "Object wasn't cleared before leaving Sub"
End If
     pointerToSomething "objcls1", lng_varPtr, ObjPtr(objcls1), coBytes
    
End Sub
On the debug-print you can see that the Initialize-Event is triggered on
Code:
Set objcls = New Class1
but objcls isn't yet set. The class is assigned a pointer, whereas the VarPtr at this stage doesn't point anywhere but Zero, but the ObjPtr contains the vtable (methods, ...) of Class1 (and whatever else comes with the class).
With ObjPtr(Me) established objcls next is assigned a pointer VarPtr which points to the instance of Class1, and at this stage also VarPtr(Me) gets the reference. Pretty sure it's just a inside thing why it is like that. One explanation might be, that this way, in case the Set of objcls fails it's easier to release memory (but that's just a home-made explanation).

But as you already said some time ago, this part isn't that important. In the moment I'm doing some examples with various objects. When it comes to charts, that's rather confusing. It's somehow weird, which pointer (VarPtr) suddenly points to another object, though I expect it pointing to yet another object.
But that's only a thing of memory management, and we don't have to dive deeper, as long at the end the references show that they got removed.

As for the other part:
I leave you struggling, assuming if you don't get it working I won't either. The snippet of the code anyway leaves too much to guess.
Reply With Quote