KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Replacing _o_OBJECT SET COLOR
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: February 13, 2023

The command OBJECT SET COLOR/_o_OBJECT SET COLOR is deprecated and it is recommended that the command OBJECT SET RGB COLORS.

The formatting of the colors in the deprecated command is a big unique and may require some formatting to properly replace it. The command takes in up to four (4) parameters.

The first is an optional Operator (*) to let the command know if an object name or filed/variable is passed.
Next is the name or field/variable.
Following that is the color.
Last is the optional parameter for an alternate color for an alternating listbox.

The formatting of the color parameters is as follows:
Color := -({Foreground color code} + {256 * {Background color})

As shown the formula for the color is a negative number that is comprised of a four digit hex value that uses the first two digits from the right for the foreground and the next two digits for the background.
The numbers are also limited to the 255 colors that 4D uses.

The OBJECT SET RGB COLORS command uses a more simplistic approach.
The first parameter is the optional operator and the second is the object name or field/variable, same as the deprecated command.
Next are the foreground color, and optional background color, and another optional alternate background color.

For the colors, CSS formatted strings, a 4 byte RGB hex value, or 4D constants can be used.

As such, to replace the command the colors must be extracted from the formula and converted to a CSS string or an RGB hex value.

Example:
_o_OBJECT SET COLOR( * ; "myListBox" ; -( 6 + (256 * 12 ) ; - ( 256 * 7 ) )

should be converted to

OBJECT SET RGB COLORS ( * ; "myListBox" ; Util_4DColorToHex( 6 ); Util_4DColorToHex (12 ) ; Util_4DColorToHex ( 7 ) )

The Util_4DColorToHex method is available from the following TechTip:
https://kb.4d.com/assetid=78505

Commented by Jody Bevan on March 4, 2023 at 9:36 AM
My OCD problem: In the second paragraph: - is a 'big' unique- should likely be -is a 'bit' unique- BTW: I love Tech Tips, and have ever since they started some decades ago. Great learning snippets.