Solved

TColorDialog question

Posted on 1998-11-29
6
242 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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