HTML color to Delphi TColor

Submitted by:Pitter Alderson

Date added:02 December, 2012

Category:Delphi

Delphi code example for HTML color to Delphi TColor

Tags: tcolor

Code Snippet:

    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}
 
 

Comments