?
Solved

Get the name of TColor

Posted on 2004-04-19
4
Medium Priority
?
568 Views
Last Modified: 2010-04-05
Hello experts!
  Is there some way that I can get the string "Red" for TColor value 0000FF, "Blue" for FF0000 and so on without having to write lots of ifs like

Var
 MyColor: TColor
 ColorName: String;
...

  ColorName := '('+IntToHex(MyColor, 8)+')';
//04192004:Shu-Look for a better way to get the color names
  If MyColor = clRed then
    ColorName := 'Red'
  Else
  If MyColor = clBlue then
    ColorName := 'Blue'
  Else
  If MyColor = clGreen then
    ColorName := 'Green'
  Else
  If MyColor = clYellow then
    ColorName := 'Yellow';


Looking forward to your help.
Thanks,
...Shu
0
Comment
Question by:snehanshu
[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
  • 2
4 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10858919
what about colorToString-function?
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 500 total points
ID: 10858953
a small sample

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    ColorDialog1: TColorDialog;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var s : string;
begin
  if ColorDialog1.Execute then
  begin
    s := ColorToString(ColorDialog1.Color);
    if pos('cl',s) = 1 then
      s := copy(s,3,maxLongInt);
    showmessage('Your Selected Color is '+s);
  end;
end;

end.


meikl ;-)
0
 
LVL 8

Expert Comment

by:Cesario
ID: 10859277
I agree with meikl,

procedure TForm1.Button1Click(Sender: TObject);
VAR
  s : String;
begin
  S := ColorToString($0000FF);
  IF S[1] <> '$'
    Then ShowMessage (copy(S,3,Length(s)-2))
    Else ShowMessage (copy(S,2,Length(s)-1))
end;
0
 
LVL 5

Author Comment

by:snehanshu
ID: 10859487
That was quick :-)
Thanks a lot, Meikl!
...Shu
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

777 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