Program GETLESS.PRG illustrates a FoxPro Foundation READ. In this example, there are two screens. Also you have access to any of the FoxPro System windows such as the Calendar/Diary, Help, the Calculator and so forth.
FoxPro 2.5 supports another type of READ, called a GET-less or Foundation READ in which there are no GET fields. It is used to manage multiple READ commands and window applications in a single interactive system. The Foundation READ normally has a VALID clause. The clause expression can be a UDF that activates and maintains control over its subordinate READ commands. The VALID clause is activated by any event that would normally terminate a READ command. The event is analyzed in the UDF and only terminates if the event is specifically intended to terminate the Foundation READ. To terminate the system the UDF returns a logical true value (.T.). The UDF returns a false value (.F.) if the Foundation READ is to remains active.
This program uses function keys F3 and F4 to activate screen and F7 to terminate the Foundation READ. ON KEY LABEL commands are used to setup the function keys to execute the appropriate procedures which activate the screens. Pressing the F3 key calls the GoState procedure which executes the STATE.SPR screen program if it is not already active. The screen program is not executed if its window is the foremost window (WONTOP()) or was the last window activated (WLAST()). The objective of this test is to prevent the maximum of five read levels from being exceeded. Function key F7 is used to terminate this program by calling procedure StopIt which clears the READs and sets QuitIt to .F..
The SetCity procedure is called from CITIES.SPR to position the CITIES.DBF database to the record with the same state shown in the STATES window. Figure 9.16 in the book shows the results of running this program. You can use any of the FoxPro accessories with GETLESS.PRG. In the figure, the STATE, CITIES, calculator windows are displayed.
Program GETLESS.PRG consists of two user-defined windows containing @ ... SAYs and GET objects, a program file, and a couple of database files which are listed as follows:
GETLESS.PRG Main program (Listing 9.9)
CITIES.SPR Screen program created using the FoxPro Screen Designer (See Listing 9.10)
CITIES.SCX Database containing the screen design for CITIES.SPR
CITIES.SCT Memo file for CITIES.SCX
STATE.SCX Database containing the screen design for STATE.SPR
STATE.SCT Memo file for STATE.SCX
STATE.SPR Screen program created using the FoxPro Screen Designer
CENSUS.DBF Database file containing population for each US state.
CITIES.DBF Database file containing population for 100 largest US cities.
The two user-defined windows are created using the MODIFY SCREEN command. The CITIES.SPR screen program is submitted for your examination in Listing 9.10.
The CITIES.SPR screen program, saves some SET parameters, defines the CITIES window, issues some @ commands, and executes the following READ command:
READ CYCLE ;
ACTIVATE _q81197g9s() ;
DEACTIVATE _q81197g9y()
This read statement contains an ACTIVATE clause and a DEACTIVATE clause. The ACTIVATE clause is called when the window is opened. It calls a snippet which calls the SETCITY procedure in GETLESS.PRG which selects the CITIES workarea and appropriately positions the CITIES.DBF database.
When the CITIES window is deactivated when another window is selected, READ calls the UDF snippet specified with the DEACTIVATE clause. This snippet clears the READ and returns a true value (.T.) which terminates the READ. The purpose of this code is to prevent the maximum read level from being exceeded. If you do not have this code, the window would be deactivated but the READ would still be active. Then the next time you activate the CITIES window you would add one READ level. Soon the maximum limit of five READ levels would be exceeded.
There is another UDF that is associated with the VALID clause on the @ command that creates the 5 push buttons at the bottom of the window. Whenever you select one of the 5 push buttons, the program calls the UDF to execute some action associated with a push button. The value of the Choice memvar designates which push button was chosen. The code associated with the Quit push button assigns a true value to QuitIt and clears all of the READs except the Foundation READ. Since QuitIt is .T., the Foundation READ also terminates.