xHarbour Reference Documentation > Statement Reference |
Declares a procedure along with its formal parameters.
[STATIC] [UTILITY] PROCEDURE <procName>( [<params,...>] ) [FIELD <fieldName,...> [IN <aliasName>]] [MEMVAR <var_Dynamic,...>] [LOCAL <var_Local> [:= <expression>] ,... ] [STATIC <var_Static> [:= <expression>] ,... ] <Statements> RETURN
Optionally, the names of parameters <params,...> accepted by the procedure can be specified as a comma separated list. These parameters have LOCAL scope within the procedure.
When the procedure is declared as STATIC PROCEDURE, it is only visible within the PRG file that contains the procedure declaration and cannot be invoked from elsewhere.
The PROCEDURE statement declares a procedure along with an optional list of parameters accepted by the function. Statements programmed in the procedure body form a self-contained part of a program that is executed when a procedure is called. Thus, tasks of a program can be split into several procedures, each of which performs a sub-task when invoked.
The body of a procedure ends with the next FUNCTION, PROCEDURE or CLASS declaration, or at the end of file, which implies that procedure declarations cannot be nested.
The execution of a procedure ends when a RETURN statement is encountered in the procedure body. A procedure does not return a value to the calling routine, only functions have a return value. The RETURN value is the only difference between functions and procedures.
When a procedure is declared with the STATIC modifier, its visibility is restricted to the PRG file that contains the STATIC PROCEDURE declaration. The names of STATIC procedures are resolved by the compiler and do not exist at runtime of a program. The names of non-STATIC procedures, also referred to as public procedures, are resolved by the linker and do exist at runtime. Thus, public procedures can be accessed by the Macro operator (&) while STATIC procedures cannot.
It is possible to declare STATIC procedures with the same symbolic name in different PRG files. A name conflict to a public procedure with the same name declared in another PRG file does not arise. However, the symbolic names of public functions, procedures or classes must always be unique.
When a procedure is invoked with values being passed to it, they are assigned to the formal parameters declared with <params,...>. All variables declared in this list are LOCAL variables and their visibility is restricted to the statements programmed in the procedure body.
The number of values passed to a procedure does not need to match the number of parameters declared. When fewer values are passed, the corresponding parameters are initialized with NIL. When more values are passed, the additional values are not asssigned to parameters but can be retrieved using function HB_AParams().
See also: | FIELD, FUNCTION, HB_AParams(), LOCAL, MEMVAR, METHOD (declaration), PARAMETERS, PCount(), PRIVATE, PUBLIC, RETURN, STATIC |
Category: | Declaration , Statements |
// The PROCEDURE statement is used in may other examples of // this documentation. See there.
http://www.xHarbour.com