?
Solved

Problem with color conversion

Posted on 2003-03-14
5
Medium Priority
?
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

800 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