xHarbour Reference Documentation > Statement Reference xHarbour Developers Network  

EXIT PROCEDURE

Declares a procedure to execeute when a program terminates.

Syntax

EXIT PROCEDURE <procName>
  [FIELD <fieldName,...> [IN <aliasName>]]
 [MEMVAR <var_Dynamic,...>]
  [LOCAL <var_Local> [:= <expression>] ,... ]

       <Statements>

[RETURN]

Arguments

EXIT PROCEDURE <procName>
This is the symbolic name of the declared procedure. It must begin with a letter or underscore followed by digits, letters or underscores. The symbolic name can contain up to 63 characters.
FIELD <fieldName>
An optional list of field variables to use within the EXIT procedure can be declared with the FIELD statement.
MEMVAR <var_Dynamic>
If dynamic memory variables, i.e. PRIVATE or PUBLIC variables, are used in the EXIT procedure, they are declared with the MEMVAR statement.
LOCAL <var_Local> [:= <expression>]
Local variables are declared and optionally initialized using the LOCAL statement.
RETURN
The RETURN statement terminates an EXIT procedure and branches control to the next EXIT procedure. After the last EXIT procedure has returned, control goes back to the operating system.

Description

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.

Info

See also:INIT PROCEDURE, PROCEDURE
Category: Declaration , Statements

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe