View Complete Thread | FoxWeb Forum Home
Search:
Date:    Msg ID:   
From:    Thread:   
Subject:   
You must never use PUBLIC variables to hold data that only apply to specific users.  In fact there are very few situations where the use of PUBLIC variables makes sense.  Following is some text on this subject that we compiled as a general answer on this topic:
 
Private VFP memory variables are not preserved between hits on the same channel and definitely not between hits across channels.  Each channel is a separate instance of VFP and there is no way to know which channel will serve the next request.  Variables and objects defined in your scripts will not be available in the next request unless they are defined as public.  You should NEVER use public variables to save user-specific information between hits.  Whenever you declare a variable as public, this variable remains in memory ONLY for that particular channel, even after the request is processed.  This means that:
 
a) Public variables only persist in the channel they were declared in.  They will not be available if the next request for a particular user is served by a different channel.
b) Public variables are shared by all users on the same channel so they can not be used to maintain state information.
 
Also, public variables are cleared from a specific channel if a run-time script error occurs.
 
In order to pass information between hits you need to use one of the techniques outlined in the "Session Management" topic of the FoxWeb documentation (http://www.foxweb.com/document/state.htm).  Some of these techniques are illustrated in the ContactMine example.
 
The only situation where public memory variables can be used is if they contain information that is not specific to a particular user or application.  For example, you should define your objects as public if their startup code takes too long and you do not want to define them at the beginning of every hit.  If you chose to define your objects as public you should make no assumptions about the state of these objects (or even about whether they exist).  Before using the objects your code should first check for their existence (IF TYPE('ObjectName') = 'O') and then, either create them, or re-initialize all properties.
 

FoxWeb Support Team
support@foxweb.com email

Sent by Joe Goldsmith on 02/25/2004 08:43:03 PM:
I am just about through with a multi-user web-based application using VFP8 and FoxWeb. I just now noticed that all of my vars start out as LOCAL. Should I use PUBLIC in each page so as not to step on another user in thesame page?

Joe