thanks Robert,
The attribute NeedAccessToLocals could not be enough . We need access to all variables. This is different to another languages and is most important. I abandon the initial question because if you can resolve the next comment i will resolve the sqlexec problem with another solution used to interact with Oracle that not support parameters like anothers
In FoxPro Environment there is something like a Table with 4 attributes with a max capability of
MVCOUNT (a config number parameter <= 65000)
- VariableName,
- VariabieVisibility,
- VariableValue,
- CallStack creation id
The variable are created in yours first assign action. The initial value of not assigned variables is by default .f.
The variable visibility declaration only create the variable name and if a variable hasn't declared visibility (private, public or local) the default visibility is private.
Ussing a bit of imagination, FoxPro does somethink like this
The Public callstack id is the first id, ej 1.
The private callstack id is the id who has private command declaration (resolved in Execution time flow )
The locals is similar to another but it is in the table with a particular id example different for each procedure
Then, Inside a procedure, function or method you can see variable names with the condition
CallStack Id <= the procedure Callstack id or has local id especific
Next a POC with a bug: parameter by ref not change private or public variables
Code: Select all
USING System
USING System.Collections.Generic
USING System.Text
FUNCTION CodeFile1 (p1, p2)
local lresult
private mresult
public _result
LOCAL localvar1, localvar2
PRIVATE privatevar1, privatevar2
PUBLIC publicvar1, publicvar2
publicvar1= "p1"
publicvar2:= "p2"
STORE 'a' TO privatevar1
privatevar2:= 'b' + 'c'
localvar1:= 12
localvar2:= 4
namevar:="localvar1"
&namevar.:= custom{}
? "Test macrosubstitution object assign ", Type(namevar) , iif(Type(namevar)="O", "Ok", "Fail")
&namevar.:= 6
? "Test macrosubstitution assign ", localvar1, iif(localvar1= 6, "Ok", "Fail li must be change Before 12 After 6")
lresult:= false
lresult:= "asdf"
lresult:= datetime()
lresult:= 1
store .f. to lresult, mresult, _result
//call 1
prueba ("localvar1",localvar1,localvar2,@lresult )
? "Test local variable changed ina a procedure by ref with @" , "lresult=", lresult, "Type(""lresult"")="+Type("lresult"), iif(Type("lresult")="N" and lresult=10, "OK", "Fail ""lresult"" must be changed to 10")
// call 2
prueba ("privatevar1",privatevar1,privatevar2,ref mresult )
? "Test private variable changed in a procedure by ref" , "mresult=", mresult, "Type(""mresult"")="+Type("mresult"), iif(Type("mresult")="C" and mresult="abc" , "OK", "Fail ""mresult"" must be changed to ""abc"" ")
// call 3
prueba ("publicvar1",publicvar1,publicvar2,@_result )
? "Test public variable changed in a procedure by ref with @", "_result=", _result, "Type(""_result"")="+Type("_result"), iif(Type("_result")= "C" and _result="p1p2", "OK", "Fail ""_result"" must be ""p1p2"", not change in line before ")
wait
RETURN
//************************************************
procedure prueba (pVarId,p1, p2, pout ref usual )
pout:= p1 + p2
? "Test visibility of variable " + pVarId + " inside a procedure" , iif(Type(pVarId)="U"," is not visible", "is visible" )
return
The output is
Hello World! Today is 14/06/2021
Test macrosubstitution object assign O Ok
Test macrosubstitution assign 6 Ok
Test visibility of variable localvar1 inside a procedure is not visible
Test local variable changed ina a procedure by ref with @ lresult= 10 Type("lresult")=N OK
Test visibility of variable privatevar1 inside a procedure is visible
Test private variable changed in a procedure by ref mresult= .F. Type("mresult")=L Fail "mresult" must be changed to "abc"
Test visibility of variable publicvar1 inside a procedure is visible
Test public variable changed in a procedure by ref with @ _result= .F. Type("_result")=L Fail "_result" must be "p1p2", not change in line before
Press any key to continue...