Parameters by value and by reference
Helper(nValue); Helper(@nValue)Distinguishes scalar value passing from caller-variable updates.
Overview
In a normal call, assigning a new number to a parameter does not replace the caller’s numeric variable. With @ at the call site, the function can update that variable by reference. Arguments are positional rather than matched by local names. This example uses only a scalar to isolate the distinction. Arrays and objects need additional shared-content analysis; passing a container does not independently copy every element. (Sources: refs. 1–2.)
Syntax
Helper(nValue); Helper(@nValue)Commented example
#Include "Protheus.ch"
User Function Ed570()
Local nValue := 10
// Only the second call can update the caller variable.
IncrementValue(nValue)
ConOut(cValToChar(nValue))
IncrementValue(@nValue)
ConOut(cValToChar(nValue))
Return Nil
Static Function IncrementValue(nValue)
nValue := nValue + 1
Return nValueAfter value call: 10. After reference call: 11. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
- Document mutable arguments and validate types before calculation. Avoid hidden effects and do not pass constants as output variables.
- Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Comments
There are no approved comments yet.
Sign in with Google or Microsoft to comment.