Solved

# Problem with color conversion

Posted on 2003-03-14
Medium Priority
218 Views
Hello,
I have make a little application that create a report as html format, and let some posibilities to customize the design.
So i need to have the hexadecimal value of color for html (background color for example).
How can I convert delphi's colors (clNavy, clRed, etc..) in TColor type to Hexadecimal ??

Thanks !

PS: Sorry for my english i'm french :-)
0
Question by:krypto2000

LVL 1

Expert Comment

ID: 8135234
Use IntToHex(ColorToRGB(color),6);
0

LVL 9

Expert Comment

ID: 8135273
function ColorToHTMLColor(const Value: TColor): string;
begin
Result := '#' + IntToHex((rgbBlue shl 16) + (rgbGreen shl 8) +  rgbRed, 6);
end;

wbr, mo.
0

LVL 1

Expert Comment

ID: 8139583

hi try this!

function TColorToHex( Color : TColor ) : string;

function TForm1.TColorToHex( Color : TColor ) : string;
begin
Result :=
{ red value }
IntToHex( GetRValue( Color ), 2 ) +
{ green value }
IntToHex( GetGValue( Color ), 2 ) +
{ blue value }
IntToHex( GetBValue( Color ), 2 );
end;

//Eks edit1.Text := TColorToHex(clYellow);
0

LVL 6

Accepted Solution

PoeticAudio earned 100 total points
ID: 8196703
Because an actual Hex conversion is different then HTML Hex you will have to switch things around  a little bit...

Function HexToHTMLhex (HEXColor: TColor): string;
var
HexStr: String;
rStr, mStr, lStr: String;
begin
HexStr := IntToHex(HEXColor, 6);
rStr := MidStr(HexStr, 5, 2);
mStr := MidStr(HexStr, 3, 2);
lStr := MidStr(HexStr, 1, 2);

Result := rStr + mStr + lStr;
end;
0

LVL 9

Expert Comment

ID: 8603899
hi, krypto :)
can you tell us why you accepted this answer? :) fully unoptimized and doing the same thing as my proposed answer? :)
wbr, mo.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
###### Suggested Courses
Course of the Month12 days, 23 hours left to enroll