1. Technology

Convert TColor to Hex & Hex to TColor

By

Here are two simple functions to convert color values from TColor to Hex (HTML) and vice versa:

~~~~~~~~~~~~~~~~~~~~~~~~~
function TColorToHex(Color : TColor) : string;
begin
   Result :=
     IntToHex(GetRValue(Color), 2) +
     IntToHex(GetGValue(Color), 2) +
     IntToHex(GetBValue(Color), 2) ;
end;

function HexToTColor(sColor : string) : TColor;
begin
   Result :=
     RGB(
       StrToInt('$'+Copy(sColor, 1, 2)),
       StrToInt('$'+Copy(sColor, 3, 2)),
       StrToInt('$'+Copy(sColor, 5, 2))
     ) ;
end;

~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» List all network drives
« Save text from Clipboard to a file

©2014 About.com. All rights reserved.