xsharp.eu • Passing parameters by reference
Page 1 of 1

Passing parameters by reference

Posted: Tue Feb 01, 2022 12:27 am
by OhioJoe
This works in VO

Code: Select all

LOCAL cParam AS STRING
cParam := " "
Joe( @cParam )
?cparam  // expecting it to be "Hello"

FUNCTION Joe( cString AS USUAL ) AS VOID STRICT
	cString := "Hello"
	RETURN
But when I try in X# I get the following error:

Code: Select all

error XS9109: Argument 1 may not be passed with the '@' prefix	
nor does it allow the "REF" keyword

??

Thanks in advance for any help

Passing parameters by reference

Posted: Tue Feb 01, 2022 1:02 am
by Chris
Hi Joe,

This indeed works in VO, but it shouldn't since the function is strongly typed to be accepting a USUAL by value, but the code is doing something very different, it is passing a STRING by reference.

If you change it to accept a STRING by reference, then it will work:

Code: Select all

FUNCTION Joe( cString REF STRING ) AS VOID STRICT
or you can define it to accept a USUAL by reference and instead type your LOCAL cParam AS STRING instead of USUAL:

Code: Select all

LOCAL cParam AS USUAL
FUNCTION Joe( cString REF USUAL) AS VOID STRICT
Finally, you could also remove strong typing form the function and it will work either way:

Code: Select all

FUNCTION Joe( cString ) AS VOID CLIPPER
but I would not suggest to do this, since you will lose all compile time checking.

Passing parameters by reference

Posted: Tue Feb 01, 2022 3:09 am
by OhioJoe
Thank you, Chris.