Posted By

icebob on 08/02/10


Tagged

html color TColor


Versions (?)

HTML color to Delphi TColor


 / Published in: Delphi
 

  1. function HtmlToColor(s:string;aDefault:Tcolor):TColor;
  2. begin
  3. if copy(s,1,1)='#' then begin
  4. s:='$'+copy(s,6,2)+copy(s,4,2)+copy(s,2,2);
  5. end
  6. else
  7. s:='clNone';
  8. try
  9. result:=StringToColor(s);
  10. except
  11. result:=aDefault;
  12. end;
  13. end;
  14.  
  15. function ColorToHtml(DColor:TColor):string;
  16. var
  17. tmpRGB : TColorRef;
  18. begin
  19. tmpRGB := ColorToRGB(DColor) ;
  20. Result:=Format('#%.2x%.2x%.2x',
  21. [GetRValue(tmpRGB),
  22. GetGValue(tmpRGB),
  23. GetBValue(tmpRGB)]) ;
  24. end; {function ColorToHtml}

Report this snippet  

You need to login to post a comment.