Wiki Home

Scatter Name Additive

Namespace: Wiki
New in VFP 8, a new ADDITIVE keyword in SCATTER NAME


The ADDITIVE keyword will add/overwrite the properties of an existing object. Prior to VFP8, SCATTER NAME was destructive, creating a new object every time.

In my opinion this enhancement is wildly useful. -- Steven Black
I agree. Here is a simple example. The program below makes a table that saves the form location and size settings when the form is closed, and uses them when the form is run again. Run the code, resize, move, or minimize the form, close the form, then run the code again. The form will appear with the size and location it had when closed. Very cool! -- Jim Saunders

local ox
close databases all
if !File('formprops.dbf')
	create database testdb
	create table FormProps (height i, width i, top i, left i, windowstate i)
	append blank
ox = Createobject('frmtest')

DEFINE CLASS frmTest AS form

	use formprops
	scatter name this additive
	use in formprops

	use formprops
	gather name this
	use in formprops


Good example, and also shows the potential danger of using Reserved Words as field names. In this case, you want the fields to overwrite the object props, but unless this is your explicit goal, you could end up with some nasty, hard-to-trace bugs as a result -- Ed Leafe

Additional caveat... when passing an object as a parameter, it is always passed by reference, since VFP3. So whatever you do to it inside the code where it's passed, happens to the original. Right - except when you scatter name to it. The moment you do it, a new local instance is created, while the object passed as a parameter remains unchanged.

Unless you scatter name ... additive. That doesn't create a new object, it works on the passed one, as expected. This distinction bit me a few times, so I'm writing it here as a reminder to myself. -- Dragan Nedeljkovich
Category VFP 8 New Features Category VFP Commands
( Topic last updated: 2012.11.14 11:06:04 AM )