Return to Snippet

Revision: 29653
at August 2, 2010 18:46 by icebob


Initial Code
function HtmlToColor(s:string;aDefault:Tcolor):TColor;
begin
  if copy(s,1,1)='#' then begin
    s:='$'+copy(s,6,2)+copy(s,4,2)+copy(s,2,2);
  end
  else
    s:='clNone';
  try
    result:=StringToColor(s);
  except
    result:=aDefault;
  end;
end;

function ColorToHtml(DColor:TColor):string;
var
  tmpRGB : TColorRef;
begin
  tmpRGB := ColorToRGB(DColor) ;
  Result:=Format('#%.2x%.2x%.2x',
                 [GetRValue(tmpRGB),
                  GetGValue(tmpRGB),
                  GetBValue(tmpRGB)]) ;
end; {function ColorToHtml}

Initial URL


Initial Description


Initial Title
HTML color to Delphi TColor

Initial Tags
html, color

Initial Language
Delphi