View Single Post
 
Old 06-25-2014, 08:57 AM
CoolBlue's Avatar
CoolBlue CoolBlue is offline Windows 7 64bit Office 2013
Advanced Beginner
 
Join Date: Jun 2014
Location: Australia
Posts: 40
CoolBlue is on a distinguished road
Default

Quote:
Originally Posted by whatsup View Post
I see your correction, but you still left out an important thing:
That's especially important for object-variables which are set to an object like "As Worksheet". That's because the lng_ObjPtr we obtain from objwks is the same as we get from ObjPtr(Sheet1). Since Sheet1 still exists when we check afterwards, it doesn't tell if the reference hold by VarPtr(objwks) has been released.
Yes, I see what you mean... I got myself confused trying to explain it. Unfortunately my time to edit it has expired already.
Quote:
Originally Posted by whatsup View Post
I have to come back on the example in my file for Run11_clsTest()....
I still don't know why
Code:
lng_objcls1 = ObjPtr(Class1)
isn't accepted, but with "Me" it works.
Its because Class1 is not an object, its a Class template if you like.
ObjPtr(Class1) is like VarPtr(LongPtr) or ObjPtr(Collection)
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. So every instance of type Class1 has its own "Me"... a pointer to itself. But a Class cannot have a pointer to itself, coz it's not an object, only a definition of a type of object.

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

Quote:
Originally Posted by whatsup View Post
I don't get what exactly you are after, but I guess you will surprise me again
Well, we will see... I'm struggling with it.
I am hoping to have something like this...
Code:
Sub testObj()
Const objBytes As Long = 32
Dim o As clReferrence
Dim lObj As Worksheet

    Set gwks = Worksheets(1)
    
    Set lObj = gwks
    Set o = New clReferrence
    o.initObject objBytes, lObj
    
    Debug.Print "Address:  " & o.Address & vbTab & "Contents:  " & o.Contents
    Debug.Print "pAddress: " & o.pAddress & vbTab & "pContents: " & o.pContents

End Sub
But its hard to pass a reference to lobj (in other words VarPtr(lobj)) into the clReferrence object. VBA tends to resolve the reference all the way to gwks and the address of the local variable is discarded when you pass it into the Class Object.
Reply With Quote