Colors in Delphi
In this column, we have a detailed look at colors in Delphi.
The type TColor is used to specify the color of a control. It is used by the Color property of many components and by a number of other properties that specify color values.
Delphi contains definitions of constants for standard TColor values. These constants map either directly to the closest matching color in the system palette (for example, clBlue maps to blue) or to the corresponding system screen element color defined in the Color section of Windows' Control Panel (for example, clBtnFace maps to the system color for button faces).
If you specify a TColor as a 4-byte hexadecimal number instead of using a pre-defined constant, the lower three bytes represent the RGB color intensities for blue, green, and red, respectively. The bytes are arranged as 0x00BBGGRR.Some of the color constants (only a small sample of many more that are available):
The function RGB()
You can also specify a color by using the function RGB() that returns a TColor value. The function takes 3
parameters, one for red, one for green and one for blue, that can range from 0 to 255. Example:
Color of a component
Some code examples for setting the color of components:
var Colr: TColor; Panel1.Color := clRed; Panel2.Color := TColor(0x006CFF6C); Panel3.Color := RGB(250, 250, 180); Colr := TColor(RGB(255, 255, 0)); Panel4.Color := Colr;
You can also set the color of a Font:
var Colr: TColor; Colr := TColor(RGB(0, 0, 180)); Font.Color := Colr; // Font of the form Label1.Font.Color := clBlue; Memo1.Font.Color := TColor(RGB(0, 110, 0));
Database Tutorials FAQ Crash Course Delphi Tips Source Code Downloads Links
© Copyright 1999-2022