[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Get the name of TColor

Posted on 2004-04-19
4
Medium Priority
?
572 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 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

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…
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…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month17 days, 14 hours left to enroll

830 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