Call By Reference: Difference between revisions

From DataFlex Wiki
Jump to navigationJump to search
Jka (talk | contribs)
m New page: Procedure doCall String ByRef sName showln "name:" sName Move "B" to sName End_Procedure .. Move "A" to sName Send doCall (&sName ) showln "name:" sName this should show...
 
Tidyup, Categorisation
Line 1: Line 1:
Call By Reference is a technique where arguments that are passed into a procedure or function are the actual memory resident values from the calling procedure.  When the value of an argument passed by reference is changed in the child procedure, the value of the argument in the parent procedure is also changed, since technically they are the same arguement.


==Example==
The following code passes a reference to the argument ''sName'' in to the procedure '''DoCall'''.
<pre>
String sName


Procedure doCall String ByRef sName  
Procedure DoCall String ByRef sName  
  showln "name:" sName
    showln "name:" sName
  Move "B" to sName
    Move "B" to sName
End_Procedure
End_Procedure




..
Move "A" to sName
Send DoCall(&sName)
showln "name:" sName
</pre>


Move "A" to sName
The output window would display:
Send doCall (&sName )
<pre>
showln "name:" sName
name:A
 
name:B
 
</pre>
 
[[Category: Basics]]
this should show
 
name:A
name:B

Revision as of 11:52, 25 November 2007

Call By Reference is a technique where arguments that are passed into a procedure or function are the actual memory resident values from the calling procedure. When the value of an argument passed by reference is changed in the child procedure, the value of the argument in the parent procedure is also changed, since technically they are the same arguement.

Example

The following code passes a reference to the argument sName in to the procedure DoCall.

String sName

Procedure DoCall String ByRef sName 
    showln "name:" sName
    Move "B" to sName
End_Procedure


Move "A" to sName
Send DoCall(&sName)
showln "name:" sName

The output window would display:

name:A
name:B