Commands and Statements

Command SAVE Foundation

Saves variables in an XPF file.

SAVE TO <cVarFile> [ALL [LIKE | EXCEPT <Wildcard>] ]
<cVarFile> specifies the name of the memory variable file where the variables are saved. The name must contain the drive and path. The file name can be specified either as a literal file name or as a character expression in parentheses. When the file name is specified without a file extension, ".XPF" is used by default.
The option ALL specifies that all visible PUBLIC and PRIVATE variables are saved in the file <cVarFile>.
LIKE <Wildcard>
<Wildcard> optionally specifies a group of variable names using the two characters * and ? as wildcard characters. If the option LIKE is specified, all PRIVATE and PUBLIC variables whose variable names match <Wildcard> are saved. If the option EXCEPT is used, all other PUBLIC and PRIVATE variables are saved in the file.

The command SAVE TO is identical in its functionality to the command dBASE or Clipper. It does not, however, support the file format of MEM files. In Xbase++, memory variables are not saved in MEM files but in XPF files. This file format allows saving arrays and code blocks on the hard disk along with the conventional data types character, date, numeric and logical.

SAVE TO saves all PRIVATE and PUBLIC variables visible at the time the command is executed to the memory variable file <cVarFile>.

The option ALL LIKE <Wildcard> specifies a group of variable names to save in the file. ? or * can be used as wildcard characters. ? stands for any single character in a variable name and * specifies any string. If the option ALL EXCEPT is used, all PRIVATE and PUBLIC variables whose names (symbol) do not match <Wildcard> are saved.

The command RESTORE FROM reads the memory variables from the file and fills them with the saved values.

Saving objects

In case of objects, only instances of a class can be saved, not the class object itself. It should also be noted that objects may have instance variables whose contents is not persistent (especially XbaseParts).

Save arrays and code blocks

// The example shows various ways to save 
// dynamic variables in a file. 

   MEMVAR cString1, cString2, aArray, aBlock, bBlock 

   PRIVATE cString1:= "James", cString2 :="Bond" 
   PUBLIC  aArray  := {1,"A",.T.,Date()} 

   PRIVATE aBlock := { {|a,b| SetPos(a,b) }           , ; 
                       {|a,b,c,d| SaveScreen(a,b,c,d)}  ; 

   PUBLIC  bBlock := {|a,b,c,d,e| RestScreen(a,b,c,d,e)} 

   SAVE TO AllVars 

   SAVE ALL LIKE a* TO ArrayVar 

   SAVE ALL LIKE ?Block TO BlockVar.XPF 

   SAVE ALL EXCEPT cString? TO SomeVars.XPF 


If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.