Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Cascading Assign bug
Message
From
23/10/2001 16:34:09
 
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00572229
Message ID:
00572320
Views:
39
Hi Glen, I believe this one's by design. It has to do with how VFP loads class definitions into memory. For class properties and methods it racks this information once. Therafter subsequent instances share this information.

To illustrate, try this:
  DEFINE CLASS RatFace AS Custom 
    nTtest= SECONDS()
  ENDDEFINE
If you instance many objects of class Ratface, all will have the same nTest property. If on the other hand you do this
  DEFINE CLASS RatFace AS Custom 
    Ntest= 0

  FUNCTION INIT
     This.ntest= SECONDS()
  ENDDEFINE
Then each instance gets its own nTest value, as you would expect.

Therefore remember this: VFP stores class definitions once, and this information is shared by all subsequent instances of the class. This is a sensible optimization that reduces both the memory footprint and instantiation times of subsequent class instances.

**--** Steve



>I have had a problem with cascading assign events. See the attacjed code for an example. The first assign executes and then quits!
>
>
>
>local lo
>clear
>lo= createobject('cascader')
>lo.changex()
>lo.showx()
>lo = ''
>
>define class cascader as container
>	iMax	=	4
>	function init
>		local i
>		for i = 1 to this.iMax
>			this.addobject('c'+transform(i),'cobj',i)
>		endfor
>	endfunc
>
>	function changex
>		set step on
>		this.c1.x = 2
>
>	function showx
>		local lxobj, i
>		for i = 1 to 4
>			lxobj = evaluate('this.c'+transform(i))
>			? 'this.c'+ transform(i) +'.x = ' + transform(lxobj.x)
>		endfor
>
>enddefine
>
>define class cObj as custom
>	x	=	0
>	i	=	0
>
>	function init
>		lpara tni
>		this.i = tni
>	endfunc
>
>	function x_assign
>		lparameters txVal
>		local lxobj
>		this.x= txVal
>		if this.i < this.parent.iMax
>			lxobj =	evaluate('this.parent.c'+transform(this.i+1))
>			lxobj = lxobj.x + (2 * this.x)
>		endif
>
>enddefine
>
>
>Anyideas? Bug or Feature?
>
>Glenn
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform