CSS color strings for better readability

Improved and simplified 4D commands just keep coming. Now you can set colors in your form objects using CSS strings instead of numeric values. Previously CSS colors for objects were declared with a 4-byte longint (e.g., 0x00RRGGBB). But if you feel more comfortable writing BLUE instead of its numeric equivalent 255 (0xFF), we’ve got good news … 4D v17 R6 makes it possible!

HDI: CSS names instead of hex values

The OBJECT SET RGB COLORS, LISTBOX SET ROW COLOR, and LISTBOX SET GRID COLOR commands now support CSS colors as strings!

This means that you now have three options when declaring a color:

$color:="blue" 
$color:="#0000FF" //or #FF
$color:="RGB(0,0,255)"

Examples

The OBJECT SET RGB COLORS command now accepts string values for foreground and background colors. The code is also easier to write and to read:

OBJECT SET RGB COLORS(*;"text";"red";"Yellow") 
//instead of OBJECT SET RGB COLORS(*;"text";0xFF0000;0xFFFF00)
 

And that’s not all! The OBJECT GET RGB COLORS command now returns CSS color values as formatted strings:

C_TEXT($front;$back)
OBJECT GET RGB COLORS(*;"rectangle";$front;$back)
ALERT($front+"/ "+$back) //returns #0000FF/ #90EE90

The same concept applies to listbox-related commands. However, it’s important to note that the LISTBOX SET ROW COLOR command will transform the CSS value into a numerical value to fill the tables associated with the listbox and its columns.

Check out the documentation for more details on the supported CSS names. 

Also, don’t miss the opportunity to see the updated commands in action with Roland’s HDI.

Avatar
• Product Marketing Manager • Intissar joined 4D in 2017 as a Product Marketing Manager. She works closely with the product, marketing, engineering, and technical support teams to highlight the ‘why’, the ‘how’, and the ‘what’ of new and updated features to different audiences. This close proximity allows her to craft messaging frameworks and write in-depth content and code samples for the 4D blog and website. After graduating with an engineer's degree in Computer Science from VINCI university, Intissar worked in several startups as a software engineer. Her hands-on experience includes software specification, design, and development, user training and support, and team management.