Difference between revisions of "Parameter Passing"

From Recital Documentation Wiki
Jump to: navigation, search
Line 1: Line 1:
 
==By VALUE / By REFERENCE==
 
==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.
 
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.
 +
  
 
<code lang="recital">
 
<code lang="recital">
Line 9: Line 10:
 
RETURN
 
RETURN
 
</code>
 
</code>
 +
  
 
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 VALUE, a copy of the memory variable is passed to the module and the original memory variable is not accessible within the called module.
Line 15: Line 17:
  
 
Function calling syntax passes parameters by VALUE by default.
 
Function calling syntax passes parameters by VALUE by default.
 +
  
 
<code lang="recital">
 
<code lang="recital">
 
MyUdf(cVAL)
 
MyUdf(cVAL)
 
</code>
 
</code>
 +
  
 
To pass by REFERENCE, the parameter should be preceded by an @ sign.
 
To pass by REFERENCE, the parameter should be preceded by an @ sign.
 +
  
 
<code lang="recital">
 
<code lang="recital">
 
MyUdf(@cREF)
 
MyUdf(@cREF)
 
</code>
 
</code>
 +
  
 
The default behaviour can also be modified using the [[SET UDFPARMS]] command.
 
The default behaviour can also be modified using the [[SET UDFPARMS]] command.
  
 
Procedure calling syntax passes parameters by REFERENCE by default.
 
Procedure calling syntax passes parameters by REFERENCE by default.
 +
  
 
<code lang="recital">
 
<code lang="recital">
 
do MyProc with cREF
 
do MyProc with cREF
 
</code>
 
</code>
 +
  
 
To pass by VALUE, the parameter must be enclosed by parentheses.
 
To pass by VALUE, the parameter must be enclosed by parentheses.
 +
  
 
<code lang="recital">
 
<code lang="recital">

Revision as of 15:10, 24 March 2009

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.

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.

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"