Tag Archives: RESTORE
SAVE
SAVE
Save variables to a memory (.mem) file
Syntax
SAVE TO <xcMemFile> [ALL [LIKE | EXCEPT <skeleton>]]
Arguments
<xcMemFile> is the memory (.mem) file to SAVE to disk. You may specify the file name as a literal string or as a character expression enclosed in parentheses. If you specify no extension, the file is created with a .mem extension.
ALL [LIKE|EXCEPT <skeleton>] defines the set of visible private and public memory variables to save to <xcMemFile>. <skeleton> is the wildcard mask that characterizes a group of memory variables to SAVE. The wildcard characters supported are * and ?.
Description
SAVE copies public and private memory variables visible within the current procedure or user-defined function to a memory (.mem) file. Arrays and local and static variables, however, cannot be SAVEd. When variables are SAVEd, they are copied without any reference to scope. Variables hidden by PRIVATE or LOCAL declarations are not SAVEd.
If you specify the ALL LIKE clause, variable names matching the <skeleton> mask are saved. By contrast, if you specify ALL EXCEPT, variable names not matching the <skeleton> are saved.
You can specify a <skeleton> that includes wildcard characters. The * wildcard character matches any group of adjacent characters ending a variable name and can be specified only at the end of the <skeleton>. The ? wildcard character matches any single character and can be specified anywhere within the <skeleton>.
Examples
. This example saves all visible private and public variables to Temp.mem: PRIVATE cOne := "1" SAVE ALL TO Temp . This example saves all visible private and public variables with names beginning with "c" to Myvars.mem: SAVE ALL LIKE c* TO MyVars . This example saves all visible private and public variables with names that do not begin with "c" to Myvars2.mem: SAVE ALL EXCEPT c* TO MyVars2
Seealso
LOCAL, PRIVATE, PUBLIC, RESTORE
C5_RESTORE
RESTORE Retrieve memory variables from a memory (.mem) file ------------------------------------------------------------------------------ Syntax RESTORE FROM <xcMemFile> [ADDITIVE] Arguments <xcMemFile> is the memory (.mem) file to load from disk. If an extension is not specified, the extension .mem is assumed. The file name may be specified as a literal string or as a character expression enclosed in parentheses. ADDITIVE causes memory variables loaded from the memory file to be added to the existing pool of memory variables. Description RESTORE is a memory variable command that recreates public and private variables previously SAVEd to a memory (.mem) file and initializes them with their former values. The scope of the variable is not SAVEd with the variable, but is instead established when the variable is RESTOREd. Arrays and local variables cannot be SAVEd or RESTOREd. When memory variables are RESTOREd, they are recreated as private variables with the scope of the current procedure or user-defined function unless they exist as public variables and you specify the ADDITIVE clause. If ADDITIVE is specified, public and private variables with the same names are overwritten unless hidden with PRIVATE. If ADDITIVE is not specified, all public and private variables are released before the memory file is loaded. Local and static variables are unaffected by RESTORE. If a local or static variable has been declared in the current procedure or user- defined function and a variable with the same name is RESTOREd, only the local or static variable is visible unless references to the RESTOREd variable are prefaced with the MEMVAR alias. Examples . This example demonstrates a typical application of SAVE and RESTORE. Here memory variables containing screens are SAVEd TO and RESTOREd FROM memory files: // Create and use a pseudoarray of screens SAVE SCREEN TO cScreen1 SAVE ALL LIKE cScreen* TO Screens // <statements>... // RESTORE FROM Screens ADDITIVE nNumber = "1" RESTORE SCREEN FROM ("cScreen" + nNumber) Files Library is CLIPPER.LIB.
See Also: LOCAL PRIVATE PUBLIC SAVE
The Art Of Simplicity
A discussion of how to create objects with Clipper using arrays, and ordinary Clipper syntax. Has several good examples.
An Introduction into Object Oriented Programming.
To me, the challenge of programming is in finding a simple clean way to implement a program. Making sure no matter how complex the specs are, the code itself stays small, strait forward, and easy to maintain.
To illustrate how to reduce the complexity of things, lets examine the box drawing routines. Normally to display a nondestructive box on the screen you write something like this:
old_row:=row() old_col:=col() old_cursor:=setcursor() old_screen:=savescreen(10, 20, 16, 59) old_color:=setcolor("w+/n, w+/r") @ 10, 20, 16, 59 BOX 'ÚÄ¿³ÙÄÀ³ '
Then when you are done and wish to remove the box, you reverse the procedure:
restscreen(10,20,16,59,old_screen) setcolor(old_color) setcursor(old_cursor) setpos(old_row,old_col)
This scheme results in using 9 lines of code, 5 memory variables, and requires that the programmer maintain the box coordinates in 3 different places. After going through this procedure a few times I started wondering if there was a better way of doing this.
When I tried to solve this problem, I had several false starts. I created a procedure to display the box that saved all the variables to statics, and the next time it was called it would restore the box. That didn’t work too well since I often wanted more than a single box on the screen.
Then I tried saving the memvars to an array that I used like a stack. But that didn’t work out too well either, since it required that all boxes be removed in the same order that they were created.
Then I decided that all the memvars being used to store the box information belonged in the calling routine, where they had been all along. Despite the fact that this seemed to bring me back to square one I continued with this train of thought.
If I stored all the memvars being used by the box routine in an array, then all the memvars could be stored in a single package, and passed to the calling routine without complications:
aBox := CreateBox(10, 20, 16, 59, "w+/n, w+/r")
And when I no longer needed the box and wished to restore the original screen:
DestroyBox( aBox )
Please compile DEMO1, to see the basic box functions.
CreateBox() and DestroyBox() are used to replace 10 lines of code, and the array aBox was used to replace 5 variables. Putting all the data into the array aBox and handling only the array, makes things much simpler.
Now that we have developed this technique, we could theoretically create a number functions that work together, like CreateBox() and DestroyBox(), and use the data contained in aBox. And in the file BOX.PRG, I have a group of sample functions that do just that:
CreateBox() DestroyBox() BoldBox() MoveBox()
Another benefit of this technique, is that we can have multiple arrays that each correspond to separate boxes, and use them all at the same time.
For example, we could write a program with a couple of boxes:
aBox1 := CreateBox( 05, 26, 20, 53, "w+/n, w+/n" ) aBox2 := CreateBox( 10, 20, 16, 59, "w+/b, w+/b" )
To move the second box:
MoveBox( aBox2, -08, -18 )
Then we could give the second box a highlight:
BoldBox( aBox2, "w+/b, w+/b" )
Then to remove both boxes:
DestroyBox(aBox2) DestroyBox(aBox1)
This example does some fairly complex things, and it does so, in only six lines of code. To run this example, compile the file DEMO2.PRG.
This programming technique has a name, it is called Object Oriented Programing (OOP).
According to OOP terminology the arrays aBox1 and aBox2 are objects, and the functions CreateBox, MoveBox, BoldBox, and DestroyBox are methods.
Objects are collections of related data, or in dBase terminology, arrays of related memvars. In our example, aBox1 and aBox2 are qualify as objects since they contain related data (the coordinates of the box, the original color, cursor position, cursor status, etc.).
In object oriented programming, several instances of an object can be created, and later destroyed when we are finished with them. In our example, aBox1 and aBox2, constitute two separate instances of box objects.
If you look at the example in DEMO3.PRG, you will see that the program creates an array of four box objects, and four separate instances of the box object are on the screen at once.
A methods is a special type of function. Methods are functions that are grouped together, and manipulate the same data objects. In the file BOX.PRG, you will see the code for four methods that use the box objects ( CreateBox, DestroyBox, BoldBox, MoveBox )
CreateBox is a special type of method called a constructor, because it creates a box object and initializes it.
DestroyBox is a special type of method called a destructor, because it destroys a box object and frees of the memory that the box object used.
Every time we call a method / function, we pass it the object we want the method to manipulate. In our example, we have two objects, aBox1 and aBox2. To move the first box, we called the method MoveBox() like this:
MoveBox( aBox1, 1, 1 )
And to bold the second box, we called the method BoldBox() like this:
BoldBox( aBox2, "w+/b,w+/n" )
The constructor CreateBox doesn’t need to be passed the object, because the constructor creates the object.
Now that you understand what an object is, you can create additional functions / methods that use the box object. And hopefully go on to create your own objects and methods.
Cynthia Allingham, 1991
/*** * * BOX.PRG * * Written By: Cynthia Allingham 11/01/91 * Purpose: Displays exploding box on the screen * Returns: Previous screen contents */
FUNC CreateBox (nTop, nLeft, nBottom, nRight, box_color)
local save_window:=savescreen(nTop, nLeft, nBottom, nRight) local save_color:=setcolor(box_color) local save_cursor:=setcursor() local save_row:=row() local save_column:=col()
@ nTop,nLeft,nBottom,nRight BOX 'ÚÄ¿³ÙÄÀ³ '
RETURN {nTop, nLeft, nBottom, nRight, save_window,; save_color, save_cursor, save_row, save_column}
/*** * Written By: Cynthia Allingham 11/01/91 * Purpose: destroys the box and restores old settings */
FUNC DestroyBox (aList)
restscreen(aList[1],aList[2],aList[3],aList[4],aList[5]) setcolor(aList[6]) setcursor(aList[7]) setpos(aList[8],aList[9]) aList:=nil return nil
/*** * Written By: Cynthia Allingham 11/01/91 * Purpose: Changes the box border */
FUNC BoldBox (aList, cColor)
@ aList[1],aList[2],aList[3],aList[4]; BOX 'ÛßÛÛÛÜÛÛ' color cColor
return nil
/*** * Written By: Cynthia Allingham 11/01/91 * Purpose: Redimensions the screen */
FUNC MoveBox (aList, nVert, nHorz)
local save_window:=savescreen(aList[1],aList[2],aList[3],aList[4])
dispbegin() restscreen(aList[1],aList[2],aList[3],aList[4],aList[5]) aList[3] += nVert; aList[1]+=nVert aList[4] += nHorz; aList[2]+=nHorz aList[5]:=savescreen(aList[1],aList[2],aList[3],aList[4]) restscreen(aList[1],aList[2],aList[3],aList[4],save_window) dispend()
return nil
* EOF BOX.PRG
/*** * * DEMO1.PRG * * Written By: Cynthia Allingham 11/01/91 * Purpose: Simple program demonstrating the creation and * destruction of a box object. */
local aBox
set procedure to box @ 00,00,24,79 box 'ÚÄ¿³ÙÄÀ³°'
aBox:=CreateBox(10, 20, 16, 59, "w+/n, w+/r")
@22,19 say padc("Press any key to destroy the box",40) inkey(10)
DestroyBox(aBox)
* EOF DEMO1.PRG
/*** * * DEMO2.PRG * * Written By: Cynthia Allingham 11/01/91 * Purpose: Demonstates the use of two box objects */
local aBox1, aBox2
set procedure to box @ 00,00,24,79 box 'ÚÄ¿³ÙÄÀ³°'
aBox1:=CreateBox(05, 26, 20, 53, "w+/n, w+/n")
message("Press any key to create a second box") aBox2:=CreateBox(10, 20, 16, 59, "w+/b, w+/b")
message("Press any key to move the second box") MoveBox(aBox2, -08, -18)
message ("Press any key to bold the second box") BoldBox(aBox2, "w+/b, w+/b")
message("Press any key to destroy both boxes") DestroyBox(aBox2) DestroyBox(aBox1)
func message(ctext) @22,19 say padc(ctext,40) inkey(10)
* EOF DEMO2.PRG
/*** * * DEMO3.PRG * * Written By: Cynthia Allingham 11/01/91 * Purpose: Demonstates the use of four box objects */
local aBox[4] local cnt
set procedure to box @ 00,00,24,79 box 'ÚÄ¿³ÙÄÀ³°'
aBox[1]:=CreateBox(05, 05, 09, 30, "w+/n, w+/n") @ 06, 07 say "box #1"
aBox[2]:=CreateBox(18, 03, 22, 14, "w+/b, w+/b") @ 20, 05 say "box #2"
aBox[3]:=CreateBox(20, 48, 22, 77, "w+/r, w+/r") @ 21, 50 say "box #3"
aBox[4]:=CreateBox(02, 64, 12, 75, "w+/gr, w+/gr") @ 03, 66 say "box #4"
for cnt:=1 to 12 inkey(0.5) MoveBox(aBox[1], +1, 0) MoveBox(aBox[2], 0,+4) MoveBox(aBox[3], -1, 0) MoveBox(aBox[4], 0,-4) next
inkey(10) for cnt:=1 to 4 DestroyBox(aBox[cnt]) next
* EOF DEMO3.PRG
C5 Variable Handling Commands
ACCEPT :
Place keyboard input into a memory variable
ACCEPT [<expPrompt>] TO <idVar>
CLEAR ALL* :
Close files and release public and private variables
CLEAR ALL
CLEAR MEMORY :
Release all public and private variables
CLEAR MEMORY
DECLARE* :
Create and initialize private memory variables and arrays
DECLARE <identifier> [[:= <initializer>], ... ]
FIELD :
Declare database field names
FIELD <idField list> [IN <idAlias>]
INPUT :
Enter the result of an expression into a variable
INPUT [<expPrompt>] TO <idVar>
LOCAL :
Declare and initialize local variables and arrays
LOCAL <identifier> [[:= <initializer>], ... ]
MEMVAR :
Declare private and public variable names
MEMVAR <idMemvar list>
MEMVARBLOCK() :
Return a set-get code block for a given memory variable
MEMVARBLOCK(<cMemvarName>) --> bMemvarBlock
PARAMETERS :
Create private parameter variables
PARAMETERS <idPrivate list>
PRIVATE :
Create and initialize private memory variables and arrays
PRIVATE <identifier> [[:= <initializer>], ... ]
PUBLIC :
Create and initialize public memory variables and arrays
PUBLIC <identifier> [[:= <initializer>], ... ]
RELEASE :
Delete public and private memory variables
RELEASE <idMemvar list>
RELEASE ALL [LIKE | EXCEPT <skeleton>]
RESTORE :
Retrieve memory variables from a memory (.mem) file
RESTORE FROM <xcMemFile> [ADDITIVE]
SAVE :
Save variables to a memory (.mem) file
SAVE TO <xcMemFile> [ALL [LIKE | EXCEPT <skeleton>]]
STATIC :
Declare and initialize static variables and arrays
STATIC <identifier> [[:= <initializer>], ... ]
STORE* :
Assign a value to one or more variables
STORE <exp> TO <idVar list>
<idVar> = <exp>
<idVar> := [ <idVar2> := ...] <exp>