Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Parameter scoping behavior
Message
From
21/10/2005 15:20:41
 
 
To
21/10/2005 12:40:34
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows 2000 SP4
Network:
Novell 6.x
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01061120
Message ID:
01061257
Views:
9
>>My co-worker created a local variable and passed it to a procedure. The procedure took the private parameter and changed it.
>>
>>I thought that the parameter should go out of scope when the procedure ends. However, the variable's value is changed in the calling program.
>>
>>UDFPARMS is set to the 'VALUE'.
>>
>>
>>LOCAL X
>>X = 1
>>Y = 1
>>DO foo WITH X
>>? X,Y
>>RETURN
>>
>>
>>PROCEDURE foo
>>PARAMETER X
>>PRIVATE Y
>>X=2
>>Y=2
>>RETURN
>>
>>
>>OUTPUT: 2,1
>>
>>In this code, Y behaves normally. It value is set to 2 in foo, and reverts to 1 in the main program. X however, is changed to 2 even though its local in main.
>>
>>Is this expected bevavior?
>>
>>The workaround is easy... dont use the same name, and prefix params with tn.
>>
>>But the mystery remains.
>
>Hans,
>
>In procedure foo you are using a PARAMETER statement which changes the variable to PRIVATE. If you use a LPARAMETER statement the LOCAL status will be preserved.
>
>HTH,

I don't think this is correct. Having an LPARAMETER doesn't change the passing by reference.
PROCEDURE GLOOP
PRIVATE X
X = "This is X"
DO FOO WITH x
? x

procedure FOO
LPARA Y
y="This is Y"
yields "This is Y" regardless of LOCAL/PRIVATE status of X in Gloop and regardless of PARA/LPARA status in Foo.

If the parameter name in Foo is X then the variable name X is visible from within Foo. If the parameter name in Foo ix Y then X is not visible in Foo. It is either LOCAL or Hidden (having been passed by reference)
Previous
Reply
Map
View

Click here to load this message in the networking platform