## DBASE TUTORIAL by Gene Head, page 72


Head.FEB LISTING 1



*  PARMS.PRG
*
*  This section of code demonstrates the two methods of
*  parameter passing:  By reference and by value.
*
*  Developed using dCLIP - The Clipper Zipper
*
CLEAR SCREEN

*
CENTER(1,"Module to demonstrate parameter passing")
CENTER(2,"By REFERENCE and By VALUE")

@ 05,00 SAY " Parameter value before calling the procedure Psquare:"
@ 07,00 SAY " Parameter value after returning from procedure Psquare:"
@ 11,00 SAY " Parameter value before executing the function Fsquare:"
@ 13,00 SAY " Parameter value after returning from function Fsquare:"
@ 15,00 SAY "                    Value returned by function Fsquare:"
*  Set initial value before calling
STORE 5 TO M_Parm
*
*  Show initial value
@ 05,60 SAY M_Parm

*  Call procedure with parameter by REFERENCE
DO Psquare WITH M_Parm

*  Even though M_Parm was never referenced in the procedure it still
*  has a new value since it was passed by reference.
*  Show new value
@ 07,60 SAY M_Parm

*  Reinitialize value before executing function
STORE 5 TO M_Parm
*
*  Show initial value
@ 11,60 SAY M_Parm

*  Show the returned value
@ 15,60 SAY Fsquare(M_Parm)
*  Show that the original is unchanged
@ 13,60 SAY M_Parm

CENTER(20, "See the difference?")
WAIT

RETURN

******  End of program.  Functions & Procedures follow ***

****************
PROCEDURE Psquare
PARAMETER s
*  Since procedures receive by reference, changing s
*  will change the value of the original passed parameter.
s = s * s
RETURN

***************
FUNCTION Fsquare
PARAMETER s
PRIVATE s
*  Since functions receive parameters by value, changing s
*  has no effect on the value of the original passed parameter.
s = s * s
RETURN (s)  && Return the value of s, squared

***************
FUNCTION CENTER
PARAMETER line, text
@ line, 40-LEN(text)/2 SAY text
RETURN (.F.)  && Return dummy value
