Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.
REPLACE FROM ARRAY
This command is another FoxPro 2.6 addition. It’s similar to GATHER, but lets you store array data in more than one table at a time. It also completes the set of commands that contains COPY TO
ARRAY and APPEND FROM
ARRAY, letting you copy data into an array, then store it back into the same records.
Beware—this is a powerful and dangerous command. It has the potential for great destruction if used carelessly. It can overwrite mounds of data in one line. Our general feeling is that you probably shouldn’t be introducing this command into new development—generally we recommend using views for updating data. We’ve included it in the documentation here to help you understand 2.x code you may be called upon to update.
REPLACE FROM ARRAY ArrayName
[ FIELDS FieldList ]
[ Scope ]
[ FOR lForExpression ]
[ WHILE lWhileExpression ]
[ NOOPTIMIZE ]
The fields in the fieldlist (or all the fields, if you omit the FIELDS clause) are filled one by one with elements of the array. Each row of the array corresponds to a record, but you have to include a Scope, FOR or WHILE clause to affect multiple records. (See “Xbase Xplained” for details on those clauses.)
If you use the FIELDS clause of REPLACE FROM ARRAY
to update multiple records of multiple tables at once, make sure you’ve set a relation between the tables. Otherwise, you’ll affect the same record over and over in tables other than the current work area.
Like REPLACE, if the table in the current work area is at end-of-file, this command doesn’t do anything.
Array elements corresponding to memo or general fields are ignored. This makes sense since the corresponding COPY TO
ARRAY creates elements for those fields, but populates them only with .F. There’s no MEMO clause here to let you work with memo data.
You probably don’t want NOOPTIMIZE. If you really think you do, check out SET OPTIMIZE
.
USE Customer
* Position on the record you want
COPY TO ARRAY aCust
* Now edit the array contents as desired
* When you're ready to update the record
REPLACE FROM ARRAY aCust