function ColorToHtml1(Color: TColor): string;
var
COL: LongInt;
begin
COL := ColorToRGB(Color);
{ first convert TColor to Integer to remove the higher bits }
{ erst TColor zu Integer, da die Unnötigen höheren Bit entfernt werden }
Result := '#' + IntToHex(COL and $FF, 2) +
IntToHex(COL shr 8 and $FF, 2) +
IntToHex(COL shr 16 and $FF, 2);
end;
function ColorToHtml2(Clr: TColor): string;
begin
Result := IntToHex(clr, 6);
Result := '#' + Copy(Result, 5, 2) + Copy(Result, 3, 2) + Copy(Result, 1, 2);
end;
function HtmlToColor(Color: string): TColor;
begin
Result := StringToColor('$' + Copy(Color, 6, 2) + Copy(Color, 4, 2) + Copy(Color, 2, 2));
end;
// Example:
procedure TForm1.Button1Click(Sender: TObject);
var
ColorTemp: TColor;
ident: string;
begin
Edit1.Text := ColorToHtml($808080); // $808080 (clGray) ----> #808080
ColorTemp := HtmlToColor(Edit1.Text); // #808080 -----> $808080 (clGray)
ColorToIdent(StringToColor(IntToStr(ColorTemp)), ident); // ---> ident = clGray
Edit2.Text := ident; // clGray
end;
|