Local variables per form

Discuss all feature requests you have for a new Servoy versions here. Make sure to be clear about what you want, provide an example and indicate how important the feature is for you

Local variables per form

Postby martinh » Mon Sep 10, 2007 11:09 am

Is it possible to have local variables per form?
Now we have local varibales per script.
And we have global variables per solutions.

But there are situations where I need local variables per form.
I would help to limit the number of global variables and to obtain a better overview of my solution
Martin
------------------------------------------------
Servoy Developer
Version 5.2.10/5.2.13
Java version 1.6 update 31
Database SQL Server 2008 R2
martinh
 
Posts: 857
Joined: Wed May 09, 2007 5:34 pm
Location: Belgium

Postby IT2Be » Mon Sep 10, 2007 9:35 pm

Yes, you can.

By simply not declaring them (var variable=blabla) but instead calling them like variable=blabla you have created a form variable.

BTW when you create a global without defining them in the dataprovider dialog they will live as globals but you will be able to maintain overview.
Marcel J.G. Trapman (IT2BE)
SAN partner - Freelance Java and Servoy
Servoy Components - IT2BE Plug-ins and Beans for Servoy
ServoyForge - Open Source Components for Servoy
User avatar
IT2Be
Servoy Expert
 
Posts: 4766
Joined: Tue Oct 14, 2003 7:09 pm
Location: Germany

Postby sean » Tue Sep 11, 2007 8:42 am

What Marcel points out is actually a dynamic global variable.

It persists beyond the execution of the method, but it's scope is global.

To achieve a true form-level variable you could use the "this" keyword.

In a form method, assigning a variable to "this" will actually bind the object to the form. But be cautious, there are other objects bound the for that you might not want to overwrite, such as the controller and data-providers.

Here's an example:

Code: Select all
// local variable - it lives and dies in the method
var localVar= "local";

// form level variable - binds object to form
this.formVar= "form";

//  dynamic global variable - dynamically creates a global variable, lives on after method terminates
dynamicGlobalVar = "global";


A subtle caveat is the precedence when referencing the variables.
The order is local, then form, then global.
...meaning that if you've defined variables of the same name, but at differing scopes, the local one will take precedence.
Example:

Code: Select all
// create dynamic global
theVar = "global";

// create form-level
this.theVar = "form";

// create the local  scope
var theVar = "local";

// print out theVar
application.output(theVar); // it prints the local var

// you have to explicitly cite the scope if you want the form level
application.output(this.theVar);



Hope this helps,
Sean
sean
 
Posts: 370
Joined: Mon May 21, 2007 6:26 pm
Location: USA

Postby IT2Be » Tue Sep 11, 2007 8:54 am

Sean, you are correct :oops:
Marcel J.G. Trapman (IT2BE)
SAN partner - Freelance Java and Servoy
Servoy Components - IT2BE Plug-ins and Beans for Servoy
ServoyForge - Open Source Components for Servoy
User avatar
IT2Be
Servoy Expert
 
Posts: 4766
Joined: Tue Oct 14, 2003 7:09 pm
Location: Germany

Postby martinh » Tue Sep 11, 2007 9:08 am

Thanks for this explanation. It is clear.
But it would be great if you could create form variables from the explorer treeview like creating global variables.
It will give a good overview in your solution
Martin
------------------------------------------------
Servoy Developer
Version 5.2.10/5.2.13
Java version 1.6 update 31
Database SQL Server 2008 R2
martinh
 
Posts: 857
Joined: Wed May 09, 2007 5:34 pm
Location: Belgium

Postby olivier melet » Tue Sep 11, 2007 9:55 am

Hi Martin,

please have a look to this topic, think you'll get some answers...

http://forum.servoy.com/viewtopic.php?t=8755

According to servoy, locals (form variables) may be introduced by version 4.

At that moment, we use a workaround, by defining a new property (private property) into the form object. We then stock information into that property. Hope this helps...
Olivier Melet
Administration et projets
InfoForm SA
olivier melet
 
Posts: 183
Joined: Mon Apr 19, 2004 3:33 pm
Location: Switzerland

Postby martinh » Tue Sep 11, 2007 10:08 am

Looks like your request is the same.
I hope it will be introduced in version 4.
I want to avoid that programmers will use some variable which are form wide, but you can't see it in the explorer treeview
Martin
------------------------------------------------
Servoy Developer
Version 5.2.10/5.2.13
Java version 1.6 update 31
Database SQL Server 2008 R2
martinh
 
Posts: 857
Joined: Wed May 09, 2007 5:34 pm
Location: Belgium


Return to Discuss Feature Requests

Who is online

Users browsing this forum: No registered users and 11 guests

cron