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)

Thanks,
John

Re: accessing parent class property? VPF8 by Dan

Dan
Fri Apr 11 11:25:36 CDT 2008

Either that or go top-down: thisform.container.property

Although, dependence that is that deeply nested could get ugly over time.

Dan

John Germany wrote:
> 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)
>
> Thanks,
> John



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

Re: accessing parent class property? VPF8 by John

John
Fri Apr 11 12:22:00 CDT 2008

thanks. I think I will keep it simple by adding a property to each form
that uses the container. That way I can just use thisform.lcsku...
thanks again.
John



"Bernhard Sander" <fuchs@no.spam> wrote in message
news:eWPRnR$mIHA.1768@TK2MSFTNGP05.phx.gbl...
> 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


Re: accessing parent class property? VPF8 by Rush

Rush
Fri Apr 11 12:38:37 CDT 2008

John Germany wrote:
> 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)
>
> Thanks,
> John
>
You may find it useful to use WITH/ENDWITH structures:

WITH this.parent.parent.parent
.lcSKU = space(25)
ENDWITH

- Rush