Commands and Statements

Statement INIT PROCEDURE Foundation

Declares a procedure which executes at the start of a program.

INIT PROCEDURE <ProcedureName> [( <Parameters,...>  )]
  [LOCAL <VarName_L> [ [:= <Expression>],...]]
 [MEMVAR <VarName_M,...>]
  [FIELD <FieldName,...> [IN <AliasName>]]
PROCEDURE <ProcedureName>
<ProcedureName> designates the name of the procedure which is executed automatically when a program starts. After all declared INIT PROCEDUREs are executed, control passes to the main routine of a program (main procedure). A procedure name must consist of alphanumeric characters, including the underscore (_), and the first character may not be a numeric character. The first 255 characters of procedure names, function names and variables are significant.
<Parameters,...> is a comma separated list which contains the names of the formal parameters. The parameters have LOCAL scope. The values assigned to the parameters are what was passed to the program from the command line.
A list of optional variables can be declared and initialized with the LOCAL statement. Their visibility and lifetime is limited to the actual function (see LOCAL statement).
<Expression> is any legal expression whose value is assigned to the corresponding variable (Initialization) using the inline assignment operator (:=).
A list of PRIVATE or PUBLIC variables can be declared with the MEMVAR statement. They must be subsequently created with the statement PRIVATE or PUBLIC (see the statements PRIVATE and PUBLIC).
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, and only the fields in the work area identified with <AliasName> are affected.
After the RETURN statement, the program continues with the next declared INIT PROCEDURE or passes the control to the Main function or procedure in the program.

INIT PROCEDURE declares start procedures which are automatically called before the main routine of an Xbase++ program takes the control. The parameters supplied on the command line are passed to each procedure declared as an INIT PROCEDURE. If a runtime error occurs during a start procedure, the program is immediately terminated.

INIT PROCEDURE routines cannot be called during program runtime. They are only visible to the startup code that maintains a list of INIT PROCEDURE routines. The order in which INIT PROCEDURE routines are called is not predictable. As soon as an INIT PROCEDURE ends, the next is called. After the last INIT PROCEDURE ends, control passes to the Main function or procedure of an Xbase++ application.

The ANNOUNCE statement declares a symbolic name for the linker. In order to link existing INIT PROCEDURE routines into a new application, the appropriate program module (PRG file) must be explicitly requested with REQUEST.

Xbase++ has three implicit init procedures which are called at program start prior to declared INIT PROCEDUREs. They are executed in the following order: 1st ErrorSys(), 2nd AppSys() and 3rd DbeSys().

To follow the program execution of INIT PROCEDUREs in the debugger, it must be started using the command line option "-i".

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


   USE Login NEW 
   REPLACE Login   WITH .T.   , ; 
   REPLACE LogDate WITH Date() , ; 
           LogTime WITH Time() 

   USE Login NEW 
   REPLACE Login   WITH .F.   , ; 
   REPLACE LogDate WITH Date() , ; 
           LogTime WITH Time() 

   LOCAL nMenuItem 

   DO WHILE .T.                     // Continuous loop 

      @ 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 
         ? "Selects DBF file" 
      CASE nMenuItem == 2 
         ? "Selects index file" 
      CASE nMenuItem == 3 
         ? "Searches data record" 
      CASE nMenuItem == 4 
         QUIT                        // Exits program 

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


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.