14

If i want to set a colour property to something thats non-standard (i.e. not something like clBlack or clRed) how can i do this? Can i set something like hexadecimal colours?

chendriksen
  • 1,026
  • 6
  • 16
  • 30

4 Answers4

16

RGB in Windows.pas

function RGB(r, g, b: Byte): COLORREF;

you can cast the result to be a TColor.

e.g

MyColour := TColor(RGB(Red,Green,Blue));
James
  • 9,774
  • 5
  • 34
  • 58
  • Normally, casting is done implicitly. A COLORREF and a `TColor` both are 32-bit integers. Hence, `MyColour := RGB(Red,Green,Blue);` will work just fine. – Andreas Rejbrand Apr 12 '18 at 10:25
12

you can use $00BBGGRR

BB = Blue
GG = Green
RR = Red

All these values can be between 0 and 255 ($00 and $FF)

SimaWB
  • 9,246
  • 2
  • 41
  • 46
  • I tried this, but it worked for me only if I used $FF on the beginning - so $FFBBGGRR – Asped Jan 12 '14 at 16:04
  • 2
    @Asped: No, the highest byte in the DWORD should be 0 for a normal colour. But maybe you are using colours with an alpha channel? If so, $FF is probably full opacity. But alpha isn't normally used in Win32 GDI. – Andreas Rejbrand Apr 12 '18 at 10:24
3

I always used RGB macro: http://delphi.wikia.com/wiki/RGB

Andrey
  • 59,039
  • 12
  • 119
  • 163
0

You might also want to check Colors in Delphi help page. If might be useful for Delphi developers who do web programming because Vcl.Graphics unit defines TColor values as clWeb____ web-friendly constants.

Many constants are already predefined and before you use them you can visually see how the colors look like. So there is no need to do RBG "mixes".

Interface Unknown
  • 713
  • 10
  • 26