tags:

views:

125

answers:

2
//clWebSnow = $FAFAFF; defined in Graphics.pas
Listbox1.Items.Add( ColorToString( clRed ) );
Listbox1.Items.Add( ColorToString( clWebSnow ) );

How can you return "WebSnow" as a string to show the color as a color constant as WebSnow?

All i can seem to get is '$FAFAFF' as a string with webcolors stored as a string while the StandardColors and ExtendedColors return the color constant values.

Example: clRed displays as Red in the listbox and displays as Red in the Label caption. clWebSnow displays as '$FAFAFF' in the listbox and displays as $FAFAFF in the label caption.

Bill

A: 

ColorToString looks color names up with an IntToIdent map using the const array "Colors" defined in Graphics.pas. Probably the only way to get around this is to use a custom Graphics.pas in which you've added new entries to the array.

Mason Wheeler
+7  A: 

Look at RGBToWebColorName in GraphUtil.

  Label1.Caption := RGBToWebColorName(clWebSnow); // returns "clWebSnow"
Bruce McGee
Thanks Bruce that worked.Thank-you
Bill Miller
If you're interested, there are some more conversion and utility methods in GraphUtils.pas for web and RGB colours.
Bruce McGee
Online documentation for GrahUtil is available here.http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/GraphUtil.html
stukelly
Ah, documentation. The developer's last resort. :) Thanks for the link.
Bruce McGee