Parameter Passing

From Recital Documentation Wiki
Jump to: navigation, search

By Value / By Reference

Parameters can be passed to procedures, programs and UDFs (User Defined Functions) by VALUE or by REFERENCE. The called module must have a PARAMETERS statement at the top of the code.


PROCEDURE MyProc
PARAMETERS cPARA1
//…
//…
RETURN


When a parameter is passed by VALUE, a copy of the memory variable is passed to the module and the original memory variable is not accessible within the called module.

When a parameter is passed by REFERENCE, the called module is given the address of the memory variable so the memory variable itself can be altered.

Functions

Function calling syntax passes parameters by VALUE by default.


MyUdf(cVAL)


To pass by REFERENCE, the parameter should be preceded by an @ sign.


MyUdf(@cREF)


The default behaviour can also be modified using the SET UDFPARMS command.

Procedures

Procedure calling syntax passes parameters by REFERENCE by default.


do MyProc with cREF


To pass by VALUE, the parameter must be enclosed by parentheses.


do MyProc with (cVAL)


Number of Parameters

The PARAMETERS() function and the PCOUNT() function return the number of parameters passed to a module.


Parameter Passing from the Operating System

When Recital Terminal Developer programs are run from the Operating System, up to nine parameters may be passed to the program (compiled .dbo or non-compiled .prg). No PARAMETERS statement is required within the program, since the arguments will be stored in automatically declared public memory variables named _para1 to _para9. The parameters will be automatically converted to upper case, unless the environment variable / symbol DB_FILECASE is set to true.

$ dbrt myapp "one" "two" "three" "four" "five" "six" "seven" "eight" "nine"