Color to string and vice versa

Posted in Algorithms

Use StringToColor and ColorToString functions. These functions are undocumented and contained in graphics module. Notes: ColorToString - if value has a special name, then this name will be display. For example, $FFFFFF - is a clWhite. StringToColor - you may use name of color here. For example, Str:='clYellow'.

procedure TForm1.Button1Click(Sender: TObject);
var
  Str:string;
begin
  Str:='$AC142F';
  Form1.Color:=StringToColor(Str);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Label1.Caption:=ColorToString($FFFFFF);
end;