Board index » delphi » Convert string to TColor?

Convert string to TColor?

Hi all,

I'm creating a custom color setting for the text of a
label control. The color is stored as a Hex value in
a string (i.e. '$00FFFFFF'). How can I then set the label
control's font color property to use this value at run-
time? The color property insists on having a TColor
value passed to it, but there's no function to convert
my string to TColor...hell, I can't find a function to
convert the string to hex.

Any ideas?

 - Dave
cyg...@mcs.com

 

Re:Convert string to TColor?


You use StrToInt to convert the string to binary, then a cast to TColor.
Like this...

        Color := TColor(StrToInt(Edit1.Text));

... for instance. In this instance, if Edit1.Text contains '$FF', you'll
get clRed back as your colour.

"David M. Fornalsky" <cyg...@mcs.com> writes:

Quote
>I'm creating a custom color setting for the text of a
>label control. The color is stored as a Hex value in
>a string (i.e. '$00FFFFFF'). How can I then set the label
>control's font color property to use this value at run-
>time? The color property insists on having a TColor
>value passed to it, but there's no function to convert
>my string to TColor...hell, I can't find a function to
>convert the string to hex.
>Any ideas?
> - Dave
>cyg...@mcs.com

--
Luke Webber

* Note: The opinions expressed by Luke Webber are in no way supported *
*       by his employers, Luke Webber Consulting Services             *

Re:Convert string to TColor?


?

Quote
David M. Fornalsky wrote:
> I'm creating a custom color setting for the text of a
> label control. The color is stored as a Hex value in
> a string (i.e. '$00FFFFFF'). How can I then set the label
> control's font color property to use this value at run-
> time? The color property insists on having a TColor
> value passed to it, but there's no function to convert
> my string to TColor...hell, I can't find a function to
> convert the string to hex.
> ?

? MyObj.Color := StrToInt(MyString);

Ex.: Label1.Color := StrToInt('$00FFFFFF');

[...Skull...]

Re:Convert string to TColor?


Hi,

Quote
>my string to TColor...hell, I can't find a function to
>convert the string to hex.

You don't want to convert a string to Hex, you want to make a binary
integer out of it. That's what IntToStr is for, look it up and find
out that it can handle Hex-Notation as well as decimal.

Then cast that integer to TColor:

   Form1.Color:=TColor(IntToStr('$00ffffff'));

Ciao, MM
--
Fon: +49 228 624013 Fax: +49 228 624031
"Was schiefgehen kann, geht auch schief."

Re:Convert string to TColor?


On Tue, 9 Dec 1997 13:07:36 -0600, "David M. Fornalsky"

Quote
<cyg...@mcs.com> wrote:
>Hi all,

>I'm creating a custom color setting for the text of a
>label control. The color is stored as a Hex value in
>a string (i.e. '$00FFFFFF'). How can I then set the label
>control's font color property to use this value at run-
>time? The color property insists on having a TColor
>value passed to it, but there's no function to convert
>my string to TColor...hell, I can't find a function to
>convert the string to hex.

Label.Font.Color := StringToColor('$00FFFFFF');

JE McTaggart

Other Threads