?
Solved

TColorDialog question

Posted on 1998-11-29
6
Medium Priority
?
250 Views
Last Modified: 2012-05-04
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
Comment
Question by:aztec
[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
  • 3
  • 2
6 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 150 total points
ID: 1348580
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
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1348581
You can also use GetRValue, GetGValue and GetBValue API functions to get the individual reb/green/blue components from a TColor.

Cheers,

Raymond.
0
 

Author Comment

by:aztec
ID: 1348582
but how do I turn it into Hexadecimal?

Shawn
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 12

Expert Comment

by:rwilson032697
ID: 1348583
Use the IntToHex function.
0
 

Expert Comment

by:huizhang
ID: 1348584
Hi,

u can use format function to get the Hexadecimal string.
0
 

Expert Comment

by:huizhang
ID: 1348585
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

770 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