Skip to content

Global Procedures and Functions

An important part of the DataFlex language is the concept of a routine. A routine is a named block of code comprising multiple statements that is designed to perform some operation. Each routine that you define can be invoked multiple times throughout your program to perform its designated operation.

A DataFlex routine can assume two forms: a Procedure or a Function. The main difference between the two constructs is that a function has a return value, while a procedure does not.

Procedures and Functions can be passed data as parameters each time they are invoked. These parameters can be passed by value or by reference. Most parameters are passed by value.

Procedures and Functions can also declare local variables.

Procedures and Functions can take two forms: they can be global or they can be object-based methods.

The scope of a global procedure and function is the entire application. Global procedures and functions may be defined anywhere within an application, and they can be called from anywhere within an application. A procedure or function is identified as being global by placing the keyword Global in the procedure or function declaration as follows:

Procedure MyProcedure
    Global
    Integer iValue
    String sValue
End_Procedure

Function MyFunction Returns String
    Global
    Integer iValue
    String sValue
End_Function

The Global keyword is required. If omitted, the procedure or function will be defined as a method (object-based).

Global procedures/functions are not object-based. This means that they cannot be augmented; they are only created once, and the name of the procedure/function cannot be used by any other global or method-based procedure or function.

Global procedures/functions should be used sparingly—use methods (object-based procedures and functions) instead.

Refer to the section on Methods to learn more about object-based procedures and functions, Parameter Passing, and Augmenting Methods.

Read more in these Global Procedures and Functions subtopics: