SCATTER & GATHER Commands Have a New NAME ArgumentID: Q129314 3.00 WINDOWS The information in this article applies to:
SUMMARYThe SCATTER and GATHER commands have a new argument (NAME <ObjectName>) that enables the Object Oriented Programming (OOP) features of Visual FoxPro. This article shows by example how to use this new argument.
MORE INFORMATION
SCATTER CommandSCATTER NAME <ObjectName> creates a row or record type of object with properties that have the same name as the fields in the table. The values of the properties are initialized to the same value as that of the fields in the table. General and memo field types do not have a property created for them in the object. The syntax for the SCATTER command is: SCATTER
GATHER CommandGATHER NAME <ObjectName> writes a row or record of values from the object to the table where the object properties have names that are identical to the table field names. The syntax for the GATHER command is: GATHER FROM <ArrayName> | MEMVAR | NAME <ObjectName>
Code SampleThe following code defines a custom class that uses the SCATTER and GATHER commands with their object argument, NAME. The code demonstrates:
ACTIVATE SCREEN CLEAR CLOSE DATABASES * The next three commands create a new table and add two new records * with values. CREATE TABLE test1 (Name C(10), Age N(3)) INSERT INTO test1 (Name,Age) ; INSERT INTO test1 (Name,Age) ;
CLOSE DATABASES
* The following command creates a new object 'oTable' from the custom * class 'Table' defined at the end of this program. It uses the table * 'test1' that was just made. The object 'oRow' is automatically * created during the creation of oTable from the SCATTER NAME <object> * command and has a property created for each field in the table. oTable=CREATEOBJECT('Table','test1') LIST * The following command sends a message to the object oTable to run the * method Next which moves the record pointer in the table ahead one. oTable.Next() * The next two commands send messages to assign new values to the * properties of oTable.oRow. oTable.oRow.Name='New Name' oTable.oRow.Age=1 * Note that the following command is calling the user defined Gather * function or method which then calls the GATHER NAME command. oTable.Gather() * The following sends a message to object oTable to run the method Previous * and assign new values to properties before writing them to the * table 'test1.dbf' with GATHER NAME command. oTable.Previous() oTable.oRow.Name='VFP' oTable.oRow.Age=0 oTable.Gather() LIST RETURN *************************** ***************************
DEFINE CLASS Table AS Custom * The keyword PROTECTED scopes the methods, properties and * objects making them only accessible to methods in the * current class definition. PROTECTED cFileName cFileName='' oRow='' * The Init event runs each time a new object is instantiated * from its class. PROTECTED FUNCTION Init(tcFileName) ENDFUNC
FUNCTION Open(tcf) ENDFUNC
FUNCTION Close ENDFUNC
FUNCTION Next ENDFUNC
FUNCTION Previous ENDFUNC
FUNCTION Scatter
ENDFUNC
FUNCTION Gather
ENDFUNC
FUNCTION Destroy ENDFUNC
ENDDEFINE * End of code sample Additional reference words: 3.00 VFoxWin KBCategory: KBSubcategory: FxprgGeneral
|
Last Reviewed: May 22, 1998 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |