Solved

Get the name of TColor

Posted on 2004-04-19
4
557 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
Comment Utility
what about colorToString-function?
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 125 total points
Comment Utility
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
Comment Utility
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
Comment Utility
That was quick :-)
Thanks a lot, Meikl!
...Shu
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

8 Experts available now in Live!

Get 1:1 Help Now