Using SAVE/RESTORE commands:Before going into saving and restoring variables to/from memo-fields of DBF, let us review the built-in Clipper commands SAVE/RESTORE. These commands are as old as clipper itself and are intended for saving names and values of variables to disk and restoring variables with values later. The values are saved to disk files with extension MEM by default.
Can save and restore PUBLIC and PRIVATE variables with values Character, Date, Logical and Numeric only. Variables with other values like DateTime, Array, Codeblock, etc.
Syntax:
- Code: Select all Expand view
SAVE TO <memFilename> [ALL [LIKE | EXCEPT <mask>]]
RESTORE FROM <memFilename> [ADDITIVE]
This is the test program to save and restore our variables, viz., Name, Birthday, Married, Tips and DoorNumber, using SAVE/RESTORE commands:
- Code: Select all Expand view
#include "fivewin.ch"
MEMVAR Name, Birthday, Married, Tips, DoorNumber
function Main()
SET DATE FORMAT TO "DD.MM.YYYY"
if File( "MYVAR.MEM" )
RESTORE FROM MYVAR ADDITIVE
Tips := &Tips
else
PUBLIC Name := "Hakan", ;
Birthday := {^ 1960/11/15 }, ;
Married := .F., ;
Tips := { "aaa", "bbb", "ccc", "ddd" }, ;
DoorNumber := 456
endif
? Name, Birthday, Married, DoorNumber
// Use the variables
EDITVARS Name,Birthday,Married,DoorNumber
XBROWSER Tips FASTEDIT TITLE "Tips"
// Finally Save
Tips := FW_ValToExp( Tips )
SAVE TO MYVAR ALL
return nil
The SAVE/RESTORE commands are very reliable and in most cases enough for saving and restoring variable names and values across sessions of the same appilcation as well as for communication between applications. A lot simpler than saving to DBF or others.
Before going to the next post, please do build and run this program. In the first run you will see the original values. Modify the values as you like. In the second run, you will see the modified values.
If for some reason, you insist on saving to DBF but not to MEM files, please see the next post.