[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

TColorDialog question

Posted on 1998-11-29
6
Medium Priority
?
253 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
Technology Partners: 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!

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

649 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