Showing posts with label delphi color. Show all posts
Showing posts with label delphi color. Show all posts

Tuesday, August 14, 2007

How to convert from HTML color to delphi color

Here is a sample of code how to convert from HTML color representation to Delphi colors:

function HtmlToColor(Color: string): TColor;
begin
Result := StringToColor('$' + Copy(Color, 6, 2) + Copy(Color, 4, 2) + Copy(Color, 2, 2));
end;


I write a small example program:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Shape1: TShape;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
function HtmlToColor(Color: string): TColor;
begin
Result := StringToColor('$' + Copy(Color, 6, 2) + Copy(Color, 4, 2) + Copy(Color, 2, 2));
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
Shape1.Brush.Color:=HtmlToColor(Edit1.Text);
Shape1.Invalidate;
end;

end.