1. Home
  2. Computing & Technology
  3. Delphi Programming

Convert RGB to TColor or How to Get More TColor values for Delphi
Beside Those Specified by "cl" Constants

By , About.com Guide

Convert RGB to a TColor

Convert RGB to a TColor

In Delphi, the TColor type is used to specify the color of an object. It is used by the Color property of many components and by a number of other properties that specify color values.

The Graphics unit contains definitions of useful constants for TColor. For example, clBlue maps to blue, clRed maps to red.

More "cl" values; "More Colors"

You can specify TColor as a specific 4-byte hexadecimal number instead of using the constants defined in the Graphics unit, the low three bytes represent RGB (red, gren, blue) color intensities for blue, green, and red, respectively.

Therefore, red can be defined as TColor($0000FF).

Convertv RBG to TColor

If you have values for red, green and blue intensities (a number from 0 to 255 - "byte" type), here's how to get the TColor value:
var
   r,g,b : Byte;
   color : TColor;
begin
   r := StrToInt(ledRed.Text) ;
   g := StrToInt(ledGreen.Text) ;
   b := StrToInt(ledBlue.Text) ;

   color := RGB(r, g, b) ;

   Shape1.Brush.Color := color;
end;
The "ledRed", "ledGreen" and "ledBlue" are three edit controls used to specify the intensity of each color component. Shape1 is a TShape Delphi control.

Delphi tips navigator:
» How to Parse TAB Delimited Files in Delphi
« IsDirectoryEmpty - Delphi function to Determine if a Directory is Empty (no files, no sub-folders)

More Delphi Programming Quick Tips
Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. Delphi 2006 Tips
  7. Convert RGB to TColor or How to Get More TColor values for Delphi Beside Those Specified by "cl" Constants

©2009 About.com, a part of The New York Times Company.

All rights reserved.