Re: accessing parent class property? VPF8 by Bernhard
Bernhard
Fri Apr 11 11:52:16 CDT 2008
Hi John,
> How do I access a class property from code.
>
> Say I've got a container that has a property (lcsku) and I'm three
> levels down. Is the only way to access the property is for me to use
> this.parent.parent.parent.lcsku = space(25)
To become independent from the nesting level, you could do something like this:
add a new property to all involved classes, lets call it ancestor.
add a new method to all involved classes, lets call it PostInit
If the class is not a container, PostInit should have these lines:
PROCEDURE PostInit
LPARAMETERS poAncestor
this.Ancestor = poAncestor
ENDPROC
if the class is a container class, PostInit should have these lines:
PROCEDURE PostInit
LPARAMETERS poAncestor
LOCAL loObject
this.ancestor = poAncestor
FOR EACH loObject IN this.objects
loObject.ancestor.PostInit(poAncestor)
ENDFOR
ENDPROC
in the init event of the top most container class add a line:
PROCEDURE init
* ...
this.PostInit(this)
* ...
ENDPROC
Then in any class you could refer to the top most container by
this.ancestor.property = somevalue
Regards
Bernhard Sander