Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is PUBLIC var per session?

Status
Not open for further replies.

billyng

Programmer
Dec 7, 2004
25
US
Hi folks,

Does the public variable only exist per session?

Thanks in advance!
 
Not sure what you mean by "session". If you launch your program from the Command Window then the public var will remain visible from the Command Window after the program terminates. It wn't be visible if you close the development environment and reopen and it won't be visible after a CLEAR MEMORY operation.

Geoff Franklin
 
Sorry, I think I mixed up the session concept with J2EE. Here is my situation. I am go to write put the VFP app to the server and let multiple users to access it. Let's say there is a PUBLIC variable called USER_ID. The value will be set when a user login to the app. If user A logs in, and the USER_ID set to "0001". In the mean time, a user B logs in and the USER_ID becomes "0002". My question is whether the USER_ID will be seen as "0002" or "0001" to user A in its session?
 
Hi billyng,

you seem to think in web application logic. In VFP you normally do desktop applications, so there is no user session concept needed.

Bye, Olaf.
 
How are you instantiating your VFP COM server objects? In certain circumstances, the PUBLIC variables will show up across certain sessions: eg: when using FOXISAPI.DLL, an arbitrary number of VFP objects are "pooled", and if a public var is set in Object #1, then a second session is established (Object #2), that second session will have a different Public object... however, when the first session ends, and a third session starts and recycles Object #1, that session will see the same public variable.

So, PUBLIC var's are not a good way to communicate across sessions, but beware that the programmer is responsible for resetting the state of an object when a session is starting (using FOXISAPI.DLL, and who-knows-what other server technologies)

- Bill

Get the best answers to your questions -- See FAQ481-4875.
 
This is what I am worried about. This sounds like the PUBLIC var is working like a static var in other languages. Thanks for your tips.
 
Hi Bill!

If you're talking about a vfp COM server, yep, that's right, public vars then may be shared. As you need a multithreaded dll for multiple users, you may experience that.

If you use a session class as the base class of the COM server, define it this way:

Define mySession As Session OlePublic
Datasession = 2 && Private Datasession
...
Enddefine

This way each instance will have it's own datasession and I think also public vars are not shared for all COM objects of that COM class. Maybe worth a try?!

I think Datasession = 2 is the default for the Session class anyway.

Bye, Olaf.
 
This sounds like the PUBLIC var is working like a static var in other languages.
I'm not sure about other languages but public's broader than VB's static. A public is available everywhere once it's been declared. It can be read and written by all program code and by the Command Window after the exe terminates. A static just preserves values between calls to a VB Sub.

Geoff Franklin
 
I'm not exactly sure what you're trying to accomplish with the USER_ID. If you want it to be seen by all users logging in, then one way is to save the information to a table such as Login.dbf.

As stated, the scope of a variable declared PUBLIC is for just that copy of the .exe running on a users PC. That's for a regular .exe not one compiled to a COM server.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top