See Also: Variable Parameter Lists, End_Procedure, Function, Procedure_Return
To define a procedure.
Procedure [Set] {message} [ {type} [ByRef] {param}… ]
…
End_Procedure
Procedure [Set] {message} For {class} [ {type} [ByRef] {param}… ]
…
End_Procedure
Procedure [Set] {message} [ {type} {param}… ]
…
End_Procedure
Procedure [Set] {message} For {class} [ {type} {param}… ]
…
End_Procedure
Procedure {name} GLOBAL [ {type} [ByRef] {param}… ]
…
End_Procedure
Procedure [Set] {message} [For {class} ] [{type} {param}… ] Returns {type}
…
End_Procedure
{message} The name of the procedure being created. {message} may be between 1 and 4096 characters in length, must start with a letter, and may not contain spaces. Recommended characters are 0-9, a-z, A-Z and _ (underscore).
{type} The data type of each parameter.
{param} The local variable name assigned for purposes of processing inside the procedure to parameter values passed on invocation.
User defined actions can be defined with procedures. A procedure can be defined within an object (or its class) or it can be defined globally. The code that performs the action must be placed between the procedure command and a matching End_Procedure command. Procedures may be defined anywhere in the program relative to the point(s) from which they are called.
The code may utilize the value of each parameter declared on the procedure command line. Each type parameter pair declares a local variable, so names may be used without concern for conflicts with any other local variables in other procedures. Any number of type parameter pairs may be used.
The action specified in procedure may be initiated from other parts of the program by sending a message of form send name value ... value, where each value ordinally corresponds to an parameter in the procedure command line.
The End_Procedure command defines the end of the procedure-definition block.
Procedure DebitAcct Number nAmount Date dCheckdate Integer bShowIt
Number nBalance
Get pnBalance To nBalance
Move (nBalance - nAmount) To nBalance
Set pnBalance To nBalance
If bShowIt ;
Send WriteDebit nBalance dCheckData iCheckNumber
End_Procedure
This procedure could be called as follows:
Send DebitAcct nTotal dToday 0
Or
Send DebitAcct of hSomeObject nTotal dToday 0
If you are augmenting a procedure (adding a procedure to a sub-class or object where the procedure is already defined in the super-class) you have the choice of forwarding the procedure message or cancelling it. If the previous example, was an augmented message, it was cancelled because the message was not forwarded. Below is an example of a forwarded message:
Procedure DebitAcct Number nAmount Date dCheckdate Integer bShowIt
If (nAmount<0) ; // if amount is less than zero always
Move 1 to bShowit // show the value.
Forward Send DebitAcct nAmount dCheckDate bShowIt
End_Procedure
The total number of parameters passed to a procedure is contained in the variable Num_Arguments. This variable can be used to check that the proper number of parameters have been passed to a procedure. Omitted parameters may cause incorrect assignment of values to the procedure's parameters. If an parameter for which no value at all was passed is accessed, the error is issued.
If the procedure set option is used, the invoking command should be of form set message {of object} to arg. A procedure of this form is usually create to simulate a property. Often a Procedure Set and Function will be created using the same name allowing the developer to access the methods as a "get/set" pair.
A Function and/or Procedure Set method declared in the same class and
with the same name as an actual property will not execute.
You may create Function and Procedure Set methods of the same name as a
property in a subclass
of the class where the property is declared,
but not in the same
class.
Read more about using procedure set in the Language Guide.
Global procedures may be defined by adding the keyword GLOBAL after the procedure name.
Procedure DoTask GLOBAL string sTaskName
:
End_Procedure
Send DoTask "StartLog"
Global procedures may be called from anywhere within an application. Since global procedures are defined outside of any object so they cannot be augmented.
The special ByRef keyword can be used to specify a parameter that is passed by reference instead of by value. When a parameter is passed by reference the code that calls the procedure must pass the address of a variable of the correct type as the parameter. By reference parameters allow the procedure to directly modify the value of the variable passed to it. For example…
Procedure AddOne Integer ByRef iValue
Move (iValue + 1) to iValue
End_Procedure // AddOne
Procedure Example
Integer iCount
for iCount from 1 to 10
Send AddOne (&iCount)
loop
End_Procedure // Example
For more information refer to Parameter Passing.
Each of the values passed to the procedure on invocation may be of any type, but their values must be convertible to the named type when used in the procedure. Type mismatches will not be detected at compile time, but will cause failures at run time.
User defined procedures may be called from within user defined procedures, down to a maximum of 18 levels, but a procedure may not be defined within the definition of another procedure.
Unlike functions, procedures should not return values. Where a value is needed to be returned to the caller, a function should be used instead.
Some legacy procedures return values. You should no longer create procedures that return values.
A Procedure Set should not take more than one parameter, since it was designed for use with properties.