function TColorToHex (Color: TColor):string ;
begin
  Result: =
    IntToHex (GetRValue (Color), 2) +
    IntToHex (GetGValue (Color), 2) +
    IntToHex (GetBValue (Color), 2);
end ;

function HexToTColor (sColor:string ): TColor;
begin
  Result: =
  RGB (
    StrToInt (# 36 + Copy (sColor, 1, 2)),
    StrToInt (# 36 + Copy (sColor, 3, 2)),
    StrToInt (# 36 + Copy (sColor, 5, 2))
  );
end ;

//test:
procedure TForm1.Button1Click (Sender: TObject);
var
  c: TColor;
  s: string ;
begin
  c: = clRed;
  s: = TColorToHex (c);
  ShowMessage (s); // FF0000 (equivalent to # FF0000 in HTML)

  s: = 'FF0000';
  c: = HexToTColor (s);
  ShowMessage (BoolToStr (c = clRed));   //-1
  Self.Color: = c;   // form will turn red
end ;