• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

TColorDialog question

Hello...
  I want to write a quick app that will display a TColorDialog box that will allow me to pick a pre-defined color...or define a new one (as TColorDialog already does). I need to have the result of my choice returned back to my app in RGB hexadecimal format like this - #FF00AA. I'm doing this so I can fool around with different colors until I find one I like, then I plan to use that color in the <BODY BGCOLOR="#FFFFFF"> statement as a background on one of my webpages. How can I do this? Right now when I choose a color, the TColorDialog returns a number like 16751238...I guess this just needs to be converted to hex, yes?

Cheers
   Shawn Halfpenny
   drumme59@sprint.ca
0
aztec
Asked:
aztec
  • 3
  • 2
1 Solution
 
rwilson032697Commented:
The numver returned by TColorDialog is a TColor - a 32 bit int holding the BGR bytes in the low order 24 bits. So to get the number you want convert it to a Hexadecimal representation switching the bytes around so they are RGB. You can ignore the high order byte (it should always be zero anyway...)

Cheers,

Raymond.
0
 
rwilson032697Commented:
You can also use GetRValue, GetGValue and GetBValue API functions to get the individual reb/green/blue components from a TColor.

Cheers,

Raymond.
0
 
aztecAuthor Commented:
but how do I turn it into Hexadecimal?

Shawn
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rwilson032697Commented:
Use the IntToHex function.
0
 
huizhangCommented:
Hi,

u can use format function to get the Hexadecimal string.
0
 
huizhangCommented:
Hi there,

I have tried the following code and it works.

procedure TForm1.Button1Click(Sender: TObject);
var
  s, s1: string;
  i: integer;
begin
  if ColorDialog1.execute then
  begin
    //use IntToHex
    edit1.text:='#'+inttohex(longInt(ColorDialog1.Color),6);
    //or use Format
    {s := format('%x', [LongInt(ColorDialog1.Color)]);
    s1:='#';
    for i:= 1 to 6-Length(s) do
      s1:= s1+'0';
    Edit1.text:=s1+s;}
  end;
end;

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now