«« Site Rescued »»

While the site is still going to move from its current host, a new site will now take its place. More Info.

The new site may have less content, but the core will now remain. And it will now play nicely with phones! Keep an eye on the DelphiDabbler Blog for news.

» Help

How to convert hex colour values into Delphi formatted ones

   
Question
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?

Untested:

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

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

« Return to contents »