Declare an initialization procedure
INIT PROCEDURE <idProcedure> [(<idParam list>)] [FIELD <idField list> [IN <idAlias>]] [LOCAL <identifier> [[:= <initializer>]]] [MEMVAR <identifer list>] . . <executable statements> . [RETURN]
INIT PROCEDURE declares a procedure that will be executed at program startup.
<idProcedure> is the name of the initialization procedure to declare. Initialization procedure names can be any length, but only the first 10 characters are significant. Names may not begin with an underscore but can contain any combination of characters, numbers, or underscores.
<idParam list> is the declaration of one or more parameter variables. Variables specified in this list are declared local.
FIELD declares a list of identifiers to use as field names whenever encountered. If the IN clause is specified, referring to the declared name includes an implicit reference to the specified alias.
LOCAL declares and, optionally, initializes a list of variables or arrays whose visibility and lifetime is the current procedure.
MEMVAR declares a list of identifiers to use as private or public memory variables or arrays whenever encountered.
RETURN passes control to the next initialization procedure or the first executable routine in the program, if no other initialization procedures are pending.
The INIT PROCEDURE statement declares a procedure that will be executed at program startup. INIT procedures are called prior to the first executable statement in a Clipper application, and are useful for performing common initialization tasks such as reading configuration settings, or opening a communications port.
INIT PROCEDUREs are executed implicitly by Clipper at program startup. The visibility of initialization procedures is restricted to the system; therefore, it is not possible to call an INIT PROCEDURE from a procedure or user-defined function. Each INIT PROCEDURE receives a copy of the DOS command line arguments used to invoke the application.
Control passes from one INIT PROCEDURE to the next until all procedures in the initialization list have been called. Control then passes to the first executable statement in the program.
The ANNOUNCE statement declares a module identifier for a source (.prg) file. Once declared, INIT PROCEDUREs are referenced by this module identifier. An application may use any number of initialization procedures by explicitly REQUESTing their module identifiers.
If an error is raised during system initialization, the system returns to DOS, and pending initialization procedures are not called.
. The following example uses both INIT and EXIT PROCEDUREs to save and restore the context of the operating system. You can have your program, "Myfile.prg", REQUEST SaveDos: ANNOUNCE SaveDos #define DOS_SCREEN 1 #define DOS_ROW 2 #define DOS_COL 3 #define DOS_CURSOR 4 #define DOS_COUNT 4 STATIC saSaveDos[ SD_COUNT ] INIT PROCEDURE dosSave() SAVE SCREEN TO saSaveDos[ DOS_SCREEN ] saSaveDos[ DOS_ROW ] := ROW() saSaveDos[ DOS_COL ] := COL() saSaveDos[ DOS_CURSOR ] := SETCURSOR() RETURN EXIT PROCEDURE dosRestore() RESTORE SCREEN FROM saSaveDos[ DOS_SCREEN ] SETPOS ( saSaveDos[ DOS_ROW ], saSaveDos[ DOS_COL ] ) SETCURSOR( saSaveDos[ DOS_CURSOR ] ) RETURN
ANNOUNCE, REQUEST, EXIT PROCEDURE