Setting form name in global issue

Hi,

I set a form name in a global field (in start up) so that it could be used all over..

globals.mainForm = forms.main;

I set the global value in a variable another method as
var mainForm = globals.mainForm ;

var btnName = “something”;

// When I tried to get the btnObj as

var btnObj = mainForm.elements[btnName];

I get an error.. The undefined value has no property. The same thing work if I directly set
var mainForm = forms.main;

I think something wrong. Could you please check

Thanks

What type is globals.mainForm?
If you want to store the object you need to make it a media global.

ROCLASI:
What type is globals.mainForm?
If you want to store the object you need to make it a media global.

It’s not an actual field created in dataproviders

It’s a runtime global variable

globals.mainForm is a global variable that you have set in the dataproviders right ? (I know it’s not a table column).

So what is the media-type of this global ?

ROCLASI:
globals.mainForm is a global variable that you have set in the dataproviders right ? (I know it’s not a table column).

So what is the media-type of this global ?

It’s not at all a field created in the design mode under dataproviders tab. It’s just a javascript global variable used within the method.

I think you know Servoy allows to declare a javascript variable as global.

for eg: you can in your method you can declare as

globals.anyName = “anything”

This value could be used in anyscript until the solution is closed

Thanks

ahmad:

ROCLASI:
globals.mainForm is a global variable that you have set in the dataproviders right ? (I know it’s not a table column).

So what is the media-type of this global ?

It’s not at all a field created in the design mode under dataproviders tab. It’s just a javascript global variable used within the method.

I think you know Servoy allows to declare a javascript variable as global.

for eg: you can in your method you can declare as

globals.anyName = “anything”

This value could be used in anyscript until the solution is closed

Thanks

I see why we didn’t understand each other at first.
As far as I know globals is a Servoy class.
I know you can define global javascript variables by not using var when assigning a variable a value for the first time.
But you are using globals.mainForm = forms.main;.
Instead you should use mainForm = forms.main;

No, Ahmad is right here.

Declaring global JavaScript variables by not putting var in front of the declaration created a global variable, but, according to the manual, the prefered way by Servoy is declaring it like globals.xxxx = value;

I think there is not much difference between the two and how the global variable is declared is probably not why Ahmad’s method isn’t working.

But, probably, it’s a clash of classes, in that a global cannot containt an form reference.

Paul

pbakker:
Declaring global JavaScript variables by not putting var in front of the declaration created a global variable, but, according to the manual, the prefered way by Servoy is declaring it like globals.xxxx = value;

I guess I should read the manual for once then ;)

Anyway, I did some testing and indeed you can’t assign a form object to a globals.xxx variable.
Without the prefix globals. however it does work.

Why read manuals?!?! We’ll tell you :D

pbakker:
probably, it’s a clash of classes, in that a global cannot containt an form reference.

Can this be fixed by Servoy people..please.. :(

because I’m puttting all my common methods in a module which needs to access some forms which is set in globals

Thanks in advance

Ahmad,

Like I said after my test, it works with global javascript variables as long as you don’t use the prefix globals.

Hope this helps.