|
#1
|
|||
|
|||
I see your correction, but you still left out an important thing:
Quote:
I have to come back on the example in my file for Run11_clsTest(). It actually doesn't show that the class got destroyed. I made an attempt to obtain the VarPtr and ObjPtr for Class1, but it didn't work therefore I left it. Now I figured it out: Class1: Code:
Public Sub Class_Initialize() Debug.Print "Class1 is initialized" lng_objcls1 = ObjPtr(Me) lng_varcls1 = VarPtr(Me) pointerToSomething "objClass1", lng_varcls1, lng_objcls1, coBytes End Sub Code:
lng_objcls1 = ObjPtr(Class1) Checking on these datas afterwards, it shows properly that the class gets terminated: Mod11_Class: Code:
Sub Run11_clsTest() Do_Header "Running Test_Class..." Test_Class DoEvents Debug.Print "After Runtime" pointerToSomething "objcls1", lng_varPtr, lng_objPtr, coBytes pointerToSomething "objClass1", lng_varcls1, lng_objcls1, coBytes End Sub Quote:
|
#2
|
||||
|
||||
Quote:
Quote:
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:
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 |
#3
|
|||
|
|||
Quote:
Quote:
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 Code:
Set objcls = New Class1 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. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Wierd "script code" in a downloaded .doc file | CNBarnes | Word | 2 | 10-18-2012 02:07 AM |
replace data from variable with "sub and super script" from excel to word by vba | krishnaoptif | Word VBA | 9 | 06-22-2012 05:08 AM |
How to choose a "List" for certain "Heading" from "Modify" tool? | Jamal NUMAN | Word | 2 | 07-03-2011 03:11 AM |
Rules and Alerts: "run a script"? | discountvc | Outlook | 0 | 06-15-2010 07:36 AM |
An "error has occurred in the script on this page" | decann | Outlook | 8 | 09-03-2009 08:54 AM |