Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting TColor to a hexadecimal color

Webpage Design

Converting TColor to a hexadecimal color

by  BobbaFet  Posted    (Edited  )
Let me be the first to admit that this isn't my own code.
I found it on the web somewhere, all I did was turn it
into a function (and add the # sign) instead of a
procedure. But my guess is that I am not the only one
looking for ways to do this hence I am posting it.

Helpful people who are making webpage software.
I suggest you use a ColorDialog in conjunction with
this function for maximum effect.

Code:
function ColorToHexColor(thisColor: TColor): string;
var RGBValue: TColorRef;
begin
RGBValue := ColorToRGB(thisColor);
Result := '#' + Format('%.2x%.2x%.2x',
                       [GetRValue(RGBValue),
                        GetGValue(RGBValue),
                        GetBValue(RGBValue)]);
end;
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top