// The example demonstrates how LOCAL variables are saved in and
// restored from an .XPF file.
// Two user-defined commands are formulated with the
// #command directive, which are translated from the preprocessor
// to a call to the procedure SaveLocal() or RestLocal().
// In both procedures, the formal parameters are declared with
// PARAMETERS.
// The parameters belong to the storage class PRIVATE and can be saved
// and read again with the command SAVE or RESTORE.
// With SaveLocal(), the values of LOCAL variables are assigned to the
// parameters and the parameters are saved.
// With RestLocal(), the LOCAL variables are passed by reference, after
// which the value of the read PRIVATE variable (saved parameter) is
// assigned to them. If you lengthen the parameter lists of SaveLocal()
// and Restlocal(), more than 10 LOCAL variables can be saved.
#command SAVE TO <(file)> LOCAL <var,...> ;
=> SaveLocal( <(file)>, <var> )
#command RESTORE FROM <(file)> LOCAL <var1> [,<varN>] ;
=> RestLocal( <(file)>, @<var1> [, @<varN>] )
PROCEDURE Main
LOCAL cString:= "Xbase++", ; // Declares LOCAL variables
dDate := Date() , ; // and initializes them
nNumber:= 100 , ;
lLogic := .T.
SAVE TO TestFile ; // Saves value of the LOCALs
LOCAL cString, dDate, nNumber, lLogic
cString := dDate := ; // Deletes all values of the
nNumber := lLogic:= NIL // locals (assigns NIL)
RESTORE FROM TestFile ; // Reads the values again
LOCAL cString, dDate, nNumber, lLogic
************************************************************
* The PPO code for RESTORE FROM...LOCAL is: *
* *
* RestLocal( "TestFile", @cString,@dDate,@nNumber,@lLogic) *
* *
* Passes the LOCAL variables by reference! *
************************************************************
? cString // Result: "Xbase++"
? dDate // Result: Date()
? nNumber // Result: 100
? lLogic // Result: .T.
RETURN
** PARAMETER variables are declared as PRIVATE variables and
** can therefore be stored in an .XPF file
PROCEDURE SaveLocal
PARAMETERS cFile, p1,p2,p3,p4,p5,p6,p7,p8,p9,p10
SAVE TO (cFile) ALL LIKE p*
RETURN
** PARAMETER variables are declared as PRIVATE variables and
** can therefore be read out of an .XPF file.
** When LOCAL variables are passed by reference, they
** receive the read values of the PRIVATE variable.
PROCEDURE RestLocal
PARAMETERS cFile, p1,p2,p3,p4,p5,p6,p7,p8,p9,p10
RESTORE FROM (cFile) ADDITIVE
RETURN