Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Class does not see its parent
Message
 
 
To
16/02/2011 09:09:19
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01500327
Message ID:
01500389
Views:
53
>>Hi everybody,
>>
>>I have a custom class (defined in a program) that has an object property defined like this
>>
>>oSomeObject = null
>>
>>In the Init I instantiate this object using
>>
>>this.oSomeObject = newobject('MyClass','myClasslib.vcx')
>>
>>Now, from that class I want to invoke methods of 'its parent'. However, oSomeObject doesn't know that it's a property of another class and therefore returns U when I check for its parent.
>>
>>What can I do to make it aware of the 'parent' class? Do I need to add Parent property and populate it? And if yes, how can I avoid dangling references?
>>
>
>The way I handle this kind of thing is to pass the instantiating class as a parameter and store it in a property of the newly instantiated class:
>
>
>* Init
>LPARAMETERS oCallingClass
>
>IF VARTYPE(m.oCallingClass) = "O"
>   This.oCaller = m.oCallingClass
>ENDIF
>
>
>As you note, you do have to clean stuff like this up. One easy way is that Destroy from the calling class calls a custom method of MyClass:
>
>
>* Calling class.Destroy
>This.oSomeObject.CleanUpReferences()
>
>*MyClass.CleanUpReferences
>This.oCaller = .null.
>
>
>For hierarchies involving collections, I actually have some in my base collection class to ensure that every member of the collection handles this clean up.
>
>Tamar

I've done something like this, but I believe I should have used a simpler suggested solution, so I was in the middle of testing it until I switched for a moment break of forums' reading.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform