xHarbour Reference Documentation > Statement Reference |
Declares a procedure to execeute when a program terminates.
EXIT PROCEDURE <procName> [FIELD <fieldName,...> [IN <aliasName>]] [MEMVAR <var_Dynamic,...>] [LOCAL <var_Local> [:= <expression>] ,... ] <Statements> [RETURN]
The EXIT PROCEDURE statement declares a procedure that is automatically called when a program terminates regularly, i.e. when the QUIT statement is executed or when control goes back to the operating system following a RETURN statement in the main routine of a program. When a program ends due to a non-recoverable runtime error, or when ALT+C is pressed, no EXIT procedure is called.
EXIT procedures do not have a list of arguments and no parameters are passed on program termination. The execution order of EXIT procedures is undetermined. It is only guaranteed that they are called when a program ends.
An EXIT procedure cannot be called explicitely during runtime of a program since its symbolic name is resolved at compile time and does not exist at runtime.
See also: | INIT PROCEDURE, PROCEDURE |
Category: | Declaration , Statements |
// The example uses INIT and EXIT procedures to make sure that all // database and index files are open at program start and properly // closed on program termination. PROCEDURE Main WAIT Browse() RETURN INIT PROCEDURE OpenDatabase CLS ? "Init program" IF ! File( "Cust1.ntx" ) USE Customer ALIAS Cust EXCLUSIVE INDEX ON Upper( LastName + FIrstName ) TO Cust1.ntx USE ENDIF IF ! File( "Cust2.ntx" ) USE Customer ALIAS Cust EXCLUSIVE INDEX ON Upper( City ) TO Cust2.ntx USE ENDIF USE Customer ALIAS Cust SHARED INDEX Cust1.ntx, Cust2.ntx RETURN EXIT PROCEDURE CloseDatabase ? "Exit program" SELECT Cust COMMIT CLOSE DATABASE RETURN
http://www.xHarbour.com