TOPIC: A Question about FieldControl styles
#1291
A Question about FieldControl styles 1 Year, 7 Months ago
Hi

When I want a field to allow only Uppercase characters I usually do

Code:


Window(
  Controller
  {
    Controls:(Vert 
               (Field style:0x0008)
              ) 
  }
)



Because the following syntax

Code:


Window(
  Controller
  {
    Controls:(Vert 
               (Field style:ES.UPPERCASE)
              ) 
  }
)



Reports a Syntax Error

Not big deal but I think the later is more readable... What I'm doing wrong??
 
 
#1293
Re:A Question about FieldControl styles 1 Year, 7 Months ago
The problem is that your Control specification is a constant, but ES.UPPERCASE is an expression.

We know ES.UPPERCASE is actually a constant but the compiler does not know this. It could look at ES at compile time, but because Suneido is dynamic, ES might be modified later.

This concept of object constants is one of the harder parts of Suneido to understand.

One solution is to change Controls to a function:

Code:

Controls()
    {
    return ['Vert' ['Field' style: ES.UPPERCASE] ]
    }



Notice we then have to quote 'Vert' and 'Field'. I use [...] because it is shorter than Object(...)

Another option is to add an uppercase: parameter to FieldControl - this might be the easiest solution, but it does not solve the problem in general. This is also a good solution because then the control definition is not specific to Windows.

Or we could change Suneido to allow this kind of expression within constants, possibly by compiling it into something like a getter function that would be evaluated when it was accessed. Possibly caching the result since it is supposed to be constant.

Another place where this is a problem is default values for parameters. We cannot write: function (style = ES.UPPERCASE) for a similar reason - default values currently must be constants.

The workaround is to say style = false and then within the function say if (style is false) style = ES.UPPERCASE

Some time I would like to change Suneido to allow expressions for default values.
 
 
andrew