For Newbie

Tuesday, 15 November 2011

Color Converting HTML to TColor in delphi



Function for converting HTML color (hex) to TColor

Function Declaration:
HkeTColor function (wHTML: string): TColor;
begin
   Result: = StringToColor ('$' + Copy (wHTML, 6, 2) + Copy (wHTML, 4, 2) +
             Copy (wHTML, 2, 2));
end;

Example of implementation:
Shape1.Brush.Color: = HKeTColor ('# DFDFDF');

Example # 2:
procedure TForm1.Button1Click (Sender: TObject);
begin
   try
     Shape1.Brush.Color: = HKeTColor (Edit1.Text);
   except
     ShowMessage ('INVALID');
   end;
end;

Share on Facebook
Share on Twitter
Share on Google+

Related : Color Converting HTML to TColor in delphi