Statement EXIT PROCEDURE Foundation

Declares a procedure which is executed at the end of a program.

Syntax
EXIT PROCEDURE <ProcedureName>
  [LOCAL <VarName_L> [ [:= <Expression>],...]]
 [MEMVAR <VarName_M,...>]
  [FIELD <FieldName,...> [IN <AliasName>]]
       <SourceCode>
 [RETURN]
Parameters
PROCEDURE <ProcedureName>
<ProcedureName> designates the name of a procedure which is automatically executed when a program terminates. After executing all procedures declared with EXIT PROCEDURE, control returns to the operating system. A procedure name must start with a letter or an underscore (_), and consist entirely of alphanumeric characters. With procedure names, function names and variables, the first 255 characters are significant.
<VarName_L,...>
With the LOCAL statement, a list of variables can be declared and initialized. The variables belong to the LOCAL storage class. Their visibility and lifetime are limited to the actual function (see the LOCAL statement).
<Expression>
<Expression> is an expression whose value is assigned to the corresponding variable using the inline assignment operator (:=).
<VarName_M,...>
With the MEMVAR statement, a list of variables can be declared which belong to the storage class PRIVATE or PUBLIC. They must be subsequently created with the PRIVATE or PUBLIC statements (see the statements PRIVATE and PUBLIC).
<FieldName,...>
The FIELD statement allows a list of variables to be declared which belong to the storage class FIELD (see the FIELD statement). If the IN option is specified, unaliased references to the fields in the <AliasName> work area are treated as though preceded by the <AliasName> alias.
RETURN
The RETURN statement passes control to the next declared EXIT PROCEDURE or back to the operating system if it occurs in the last EXIT PROCEDURE.
Description

The EXIT PROCEDURE statement is used to declare closing procedures that are automatically called before an Xbase++ program has ended and before control returns to the operating system. They are only called when a program terminates by the QUIT command or by the RETURN statement from the main procedure or function of a program. If a program terminates due to a runtime error or after pressing Alt+C, no EXIT PROCEDUREs are executed.

EXIT PROCEDURE routines have no parameters and cannot be explicitly called during program execution. They are only known to the system, which executes a list of EXIT PROCEDURE routines. The order in which the EXIT PROCEDURE routines are called is not predictable. After completion of the last exit procedure, control returns to the operating system. If a runtime error occurs within an exit procedure, the program immediately terminates.

With the ANNOUNCE statement, a symbol can be declared. In order to link existing EXIT PROCEDURE routines to a new application, the corresponding program module must be explicitly requested with REQUEST.

Xbase++ has an implicit exit procedure AppExit() which is called each time a program ends. It can be modified to meet a user's needs (-> APPEXIT.PRG).

Examples
EXIT PROCEDURE usage
// The example shows INIT and EXIT procedures being used to time the 
// running of a program. The INIT procedure records the start time and 
// the EXIT procedure records the end time. 

ANNOUNCE Logbook 

INIT PROCEDURE LogIn() 
   USE Login NEW 
   APPEND BLANK 
   REPLACE Login   WITH .T.   , ; 
   REPLACE LogDate WITH Date() , ; 
           LogTime WITH Time() 
   USE 
RETURN 

EXIT PROCEDURE LogOut() 
   USE Login NEW 
   APPEND BLANK 
   REPLACE Login   WITH .F.   , ; 
   REPLACE LogDate WITH Date() , ; 
           LogTime WITH Time() 
   USE 
RETURN 

PROCEDURE Main 
   LOCAL nMenuItem 

   DO WHILE .T.                     // Continuous loop 

      CLS 
      @ 2, 1 PROMPT " DBF file " 
      @ 4, 1 PROMPT " NTX file " 
      @ 6, 1 PROMPT " Search    " 
      @ 8, 1 PROMPT " Quit     " 

      MENU TO nMenuItem 
      SetPos( 0, 0 ) 

      DO CASE 
      CASE nMenuItem == 1 
         ? "Select DBF file" 
      CASE nMenuItem == 2 
         ? "Select index file" 
      CASE nMenuItem == 3 
         ? "Search data record" 
      CASE nMenuItem == 4 
         QUIT                        // Exits program 
      ENDCASE 

      ? "Press a key..." 
      Inkey(0)                       // Wait... 
   ENDDO 

RETURN 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.