>I am trying learn how to use the _vfp.setvar() method to create variables on the main vfp application object that can be accessed from any form using the _vfp.eval() method.
>
>I am having trouble understanding the scope of the _vfp.setvar() calls...
>
It creates a private in the scope of the calling procedure if it does not already exist.
>If I create the object variable using _vfp.setvar() in my main .prg file (before any forms are called), they seem to be "public", in that any of the forms that might be launched can access the variables using the _vfp.eval() method.
>
>However, if I create a new variable (call it "nEmployee")using _vfp.setvar() from within a form, and then close that form, and open another form, and try _vfp.eval("nEmployee"), it says that variable does not exist.
>
>Basically I want a way to create and set publicly available variables to exchange data between forms. I thought this might be a good way. And it is... as long as you make the _vfp.setvar() call from the main .prg file.
>
Are you expecting different behavior than
PUBLIC gnEmployee
would provide.
If you're doing OOP, public variables are a bad inter-object communication method, because the use of publics breaks encapsulation. If two forms need to exchange data, you can pass their own object refs if you need to have one for look at something 'inside' another, or better, create and pass parameter objects explicitly.
>Perhaps someone can teach me a better way to achieve this.