Solved

Get the name of TColor

Posted on 2004-04-19
4
560 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
  • 2
4 Comments
 
LVL 27

Expert Comment

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

Accepted Solution

by:
kretzschmar earned 125 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

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

Suggested Solutions

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…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

867 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

13 Experts available now in Live!

Get 1:1 Help Now