Solved

Get the name of TColor

Posted on 2004-04-19
4
561 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 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