Specify colours in Morfik’s Browser Side Code

This quest started when I tried to change the colour of a control in browser side code the same way that it is done in server side code, by assigning a colour constant, like clRed, to the control’s Color property. Imaging my surprise when I got ‘Undeclared identifier’ errors for all of the ‘cl’ constants. After much research and some back and forth with Morfik’s support people I found that there are several ways of setting the colours in browser side code.

  1. You can assign a hex constant to the Color property. You simply specify the blue, green and red values as a single hex constant like this: $ff0000 for blue, $00ff00 for green and $0000ff for red.
  2. You can assign the result of the RGB function to the Color property like this: RGB($00, $00, $ff) for blue, RGB($00, $ff, $00) for green and RGB($ff, $00, $00) for red.
  3. You can use the control’s DOMStyle.backgroundColor property. When using the DOMStyle properties you must assign the correct HTML style attribute to the property. So for colour properties you assign a string like ‘red’, ‘green’ or ‘blue’.
  4. Finally, you can assign the ‘cl’ constants to the control’s Color property but to be able to do this you must copy the definition of these constants from the server side code of the SystemClasses module into the project’s Globals module. Once you have done this you can use them on the browser side just as you do on the server side. In fact, this approach will work for many of the constants that are available on the server side but not on the browser side, like cursors, etc.

Leave a Reply