Notice Of Closure

Please note that this website is due to close down on 15th June 2020.

In the interim I will try to move as much content as possible over to my GitHub account. Thanks to everyone who has supported the site over the years.

» Help

How to convert hex colour values into Delphi formatted ones

Is there a routine that can take a hex color value and convert it to a Delphi formatted value like: "Cornsilk1 Cornsilk1 255 248 220 #FFF8DC" into $00DCF8FF?


function Swap32(aLong: Longint): Longint; assembler;
  BSWAP eax

function HexColorToColor(HexColor: string): TColor;
  {input: '#FFF8DC' -> output $DCF8FF as TColor,
  use IntTohex to convert output to string again if needed}
  Assert(Length(hexcolor)) > 1);
  Assert(hexcolor[1] = '#');
  hexcolor[1] := '$';
  Result := Swap32(StrToInt(hexcolor));
Original resource: The Delphi Pool
Author: Peter Below
Added: 2009-11-06
Last updated: 2009-11-06

« Return to contents »