?
Solved

Problem with color conversion

Posted on 2003-03-14
5
Medium Priority
?
218 Views
Last Modified: 2010-04-04
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
Comment
Question by:krypto2000
5 Comments
 
LVL 1

Expert Comment

by:SimesA
ID: 8135234
Use IntToHex(ColorToRGB(color),6);
0
 
LVL 9

Expert Comment

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

wbr, mo.
0
 
LVL 1

Expert Comment

by:Svisj
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

by:
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

by:mocarts
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

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

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

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question