global == does not work

Servoy Developer
Version 3.0b3-build 364
Java version 1.5.0-b64 (Windows XP)

The following simple code example does not work as expected:

globals.gbCancel = true;

if( globals.gbCancel == true )
{
    application.beep();
}
else
{
    application.beep();
    application.beep();
}

As far as I can see it should work. Global gbCancel exists. Here I set it immediately before I use it. Tracing through with the debugger I see that the if statement never evaluates to true and the else branch is taken every time.

If I don’t use a global it works. But, of course its a global I need in the real code.

I’m posting here before reporting it officially. Maybe I’m doing something dumb.

Terry

Looks like a problem connected with the type of the global variable. Servoy supoosedly supports Boolean values. This is clearly stated in the ServoyAdvancedProgrammerGuideFMP:

Boolean data type
Boolean data types take on one of two possible values - true or false. A
boolean literal is indicated by using true or false directly in the code.
Example:
var booleanData = true;

But the Specify Global dialog does not support that data type!

So if you create a global and give it a default value of true, no quotes, then any comparison such as:

globals.gbCancel = true;

if( globals.gbCancel == true )
{

will always evaluate to false, since “true” the string is not equal to true the boolean value.

This is a serious omission in functionality. At the very least it should be highlighted in the documentation.

Servoy engineers, please don’t write to tell me that real programmers don’t use global Boolean values.

Servoy documenters, please include this information in the documentation.

Terry

don’t declare the global in the define global dialog.

Just do globals.gbCancel = true; in your code without making one
If you want to make it there. Then make it a MEDIA field.

johan

Thanks Johan.

I doubt that anyone would have guessed to use MEDIA for Boolean.

Terry

tkilshaw:
Thanks Johan.

I doubt that anyone would have guessed to use MEDIA for Boolean.

Terry

Terry,

We do appreciate your valuable input.

Our goal is to produce Servoy documentation - for online, pdf, and
printed formats - that can function as a useful tool in the process of
developing Servoy solutions. In the next Servoy documentation update,
we will expand and clarify the information that addresses Servoy global
datatypes.


Marc Norman
Servoy

MEDIA type means that the global doesn’t do any conversion to the right type. What you put in will be get out as is.
So thats why a boolean works. But maybe we can introduce also a Boolean type but you don’t need those a lot only when you really want a boolean type in scripting.

johan