Solved

TColorDialog question

Posted on 1998-11-29
6
243 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
  • 3
  • 2
6 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 50 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now