SET PROCEDURE
Opens a dBASE Plus program file as a procedure file, making its functions, classes, and methods available for execution.
Syntax
SET PROCEDURE TO
[<filename> | ? | <filename skeleton>] [ADDITIVE][PERSISTENT]
<filename> | ? | <filename skeleton>
The procedure file to open. The ? and <filename skeleton> options display a dialog box, from which you can select a file. If you specify a file without including its path, dBASE Plus looks for the file in the current directory, then in the path you specify with SET PATH. If you specify a file without including its extension, dBASE Plus assumes .PRO (a compiled object file). If dBASE Plus can't find a .PRO file, it looks for a .PRG file (a source file). If dBASE Plus finds a .PRG file, it compiles it.
ADDITIVE
Prior to dBASE Plus version 2.50
Opens the procedure file(s) without closing any you've opened with previous SET PROCEDURE statements. SET PROCEDURE TO < filename> (without the ADDITIVE option) closes all procedure files you've opened with previous SET PROCEDURE statements other than those tagged PERSISTENT.
Starting with dBASE Plus version 2.50
SET PROCEDURE TO <filename> acts as if ADDITIVE was included. In other words, SET PROCEDURE TO <filename> (without specifying ADDITIVE) will NOT close any open procedure files
PERSISTENT
Opens the procedure file with the PERSISTENT designation and, unless it is specifically referenced in the CLOSE PROCEDURE<filename list>, prevents it from being closed by any means other than CLOSE PROCEDURE PERSISTENT, CLOSE ALL PERSISTENT, or by compiling the file with COMPILE <filename>.
All SET PROCEDURE TO statements, streamed in the form class definition, will have a PERSISTENT designation when the form's persistent property is set to true in The Form Designer.
Description
To execute a function or method, that function must be loaded in memory. To be more precise, a simple pointer to that function must be in memory. The contents of the function itself are not necessarily in memory at any given time; if not, the contents get loaded into memory automatically when the function is executed. But if that function’s pointer is in memory, it is considered to be loaded.
Whenever you execute a program file with DO (or with the call operator), it is loaded implicitly; pointers to all of the functions, classes, and methods in that file are loaded into memory. Therefore, code in a program file may always call any other functions or methods in the same file.
To access functions, classes, and methods in other program files, load the program file with SET PROCEDURE first. Its function pointers stay in memory until the program file is unloaded with CLOSE PROCEDURE or SET PROCEDURE TO (with no options).
dBASE Plus uses a reference count system to manage program files in memory. Each loaded program file has a counter for the number of times it has been loaded, either explicitly with SET PROCEDURE or implicitly. As long as the count is more than zero, the file stays loaded. Calling CLOSE PROCEDURE reduces the count by one. Therefore, if you issue SET PROCEDURE twice, you need to issue CLOSE PROCEDURE twice to close the program file.
A program file’s load count has no impact on memory; it is simply a counter. Loading a program file 10 times uses the same amount of memory as loading it once.
Whenever a function is called, dBASE Plus looks for the routine in specific places in a specific order. After searching the program files in the call chain, dBASE Plus looks in files opened with SET PROCEDURE. See the DO command for an explanation of the search path and order.
To make the file containing the currently executing routine a procedure file—for example, after creating an object, to make the object’s methods which are defined in the same file available to it—execute the following statement:
set procedure to program(1) additive
Some operations, such as assigning a menuFile to a form or opening a form defined in a WFM file, automatically open the associated file as a procedure file, and that statement is not necessary.
If you issue SET PROCEDURE TO with no options, dBASE Plus closes all procedure files opened with SET PROCEDURE other than those tagged PERSISTENT. If you want to close only specific procedure files, use CLOSE PROCEDURE. The maximum number of open procedure files depends on available memory.
Note A common mistake is to forget the ADDITIVE clause when opening a procedure file. This will close all other open procedure files not tagged PERSISTENT.
When dBASE Plus executes or loads a program file, it will automatically compile the program file into object code when either:
There is no object code file, or
SET DEVELOPMENT is ON, and program file is newer than the object code file (the source code file’s last update date and time is later than the object code file’s)
If a file is opened as a procedure file and the file is changed in the Source editor, the file is automatically recompiled so that the changed code takes effect immediately.
Use TYPE( ) to detect whether a function, class, or method is loaded into memory. If so, TYPE( ) will return "FP" (for function pointer), as shown in the following IF statements:
if type( "myfunc" ) # "FP" // Function name
if type( "myclass::myclass" ) # "FP" // Class constructor name
if type( "myclass::mymethod" ) # "FP" // Method name