KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Converting constant color to an RGB value
PRODUCT: 4D | VERSION: 14.x | PLATFORM: Mac & Win
Published On: September 16, 2015

There are 16 color constants that 4D provides. Exsisting code may utilize these constants in previous versions of 4D but if one would like to extend it to RGB, here is a utility shown below:

// ---------------------------------------------------------------------------
// Name: CONVERT_CONST_COLOR_TO_RGB
// Description: Method will take in the constant color 0-15 value and convert
// to the RGB representation.
//
// Parameter:
// $1 (LONGINT) - Color constant value
//
// Output:
// $0 (LONGINT) - Color in RGB
// --------------------------------------------------------------------------
C_LONGINT($1;$const_color)
C_LONGINT($0;$rgb_color)

If (Count parameters=1)
   $const_color:=$1

   Case of
      : ($const_color=0) // White
      $0:=0x00FFFFFF
      : ($const_color=1) // Yellow
      $0:=0x00FFFF00
      : ($const_color=2) // Orange
      $0:=0x00FFA500
      : ($const_color=3) // Red
      $0:=0x00FF0000
      : ($const_color=4) // Purple
      $0:=0x00800080
      : ($const_color=5) // Dark Blue
      $0:=0x0000008B
      : ($const_color=6) // Blue
      $0:=0x000000FF
      : ($const_color=7) // Light Blue
      $0:=0x00ADD8E6
      : ($const_color=8) // Green
      $0:=0x00008000
      : ($const_color=9) // Dark Green
      $0:=0x00006400
      : ($const_color=10) // Dark Brown
      $0:=0x00654321
      : ($const_color=11) // Dark Grey
      $0:=0x00A9A9A9
      : ($const_color=12) // Light Grey
      $0:=0x00D3D3D3
      : ($const_color=13) // Brown
      $0:=0x00A52A2A
      : ($const_color=14) // Grey
      $0:=0x00808080
      : ($const_color=15) // Black
      $0:=0x0000
    Else
      $0:=0x0000 // Black
   End case

   Else
      $0:=0x0000 // Black
End If


Here is an example of setting the font color of an rectangle object:

OBJECT SET RGB COLORS(*;"Rectangle";Background color;convert_const_color_to_rgb (blue))


Result of the rectangle object set to blue:




See Also: