What is the life of a form variable?

Questions and answers for designing and implementing forms in Servoy

What is the life of a form variable?

Postby Westy » Sun Oct 11, 2015 7:29 pm

How long does a form variable remain available in a session?

I assume it is tied to the life of its form. How long does a form persist? Are forms swapped in and out of memory within a session?

Dean
Westy
 
Posts: 852
Joined: Fri Feb 13, 2004 5:27 am
Location: Lynnfield, Massachusetts USA

Re: What is the life of a form variable?

Postby mboegem » Sun Oct 11, 2015 10:54 pm

Hi Dean,

indeed the form variable is bound to the form and therefor has the same lifespan.
whetter a form remains in memory during a session depends on a couple of variables:
- is the form pushed out of the cache to load other forms which are needed
- how often is a particular form used (least used forms are pushed out first)

Best practice is to not depend on variables used on a form, referencing this from a different scope. (no cross-reference of forms / shared state)
When you need to rely on certain variables, put them in a top-level scope (ie. globals, but other top-level scopes are preferred)
And as you can conclude from above: always take care of (re)initialising form variables. (use onLoad/onUnload (when removed from cache), onShow/onHide)

Hope this will clarify the behaviour in order to choose the right approach.
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image

Partner of Tower - The most powerful Git client for Mac and Windows
User avatar
mboegem
 
Posts: 1742
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: What is the life of a form variable?

Postby Westy » Mon Oct 12, 2015 4:34 pm

Hi Marc,

Thank you for your reply. What are some examples of top level scopes for variables other than globals?

Dean
Westy
 
Posts: 852
Joined: Fri Feb 13, 2004 5:27 am
Location: Lynnfield, Massachusetts USA

Re: What is the life of a form variable?

Postby Bernd.N » Mon Oct 12, 2015 7:05 pm

Hi Dean,

I guess there are many ways to work with scopes, here is one:
We use a module "base" which holds a form "_base" which is the base root of all other forms in other modules (via several inheritance steps).
In that module "base", we defined about 29 scopes for all main modules respectively themes, e.g. scopes.person, scopes.project or scopes.security .

That way, all scopes are global, and a variable can be accessed everywhere, like scopes.person.currentPersonID (which holds the UUID of the current user).
So our global variables are distributed to several top-level scopes, which makes it easier to keep them apart and to guess the context to which they belong.

In other words, to answer your question, you can define yourself any top-level scopes you need.
Bernd Korthaus
LinkedIn
Servoy 7.4.9 SC postgreSQL 9.4.11 Windows 10 Pro
User avatar
Bernd.N
 
Posts: 544
Joined: Mon Oct 21, 2013 5:57 pm
Location: Langenhorn, North Friesland, Germany

Re: What is the life of a form variable?

Postby Westy » Mon Oct 12, 2015 9:20 pm

Thank you Marc and Bernd.

Dean
Westy
 
Posts: 852
Joined: Fri Feb 13, 2004 5:27 am
Location: Lynnfield, Massachusetts USA


Return to Forms

Who is online

Users browsing this forum: Google [Bot] and 2 guests