Back
Lennie's Weekly Tip: Converting Color into Hexadecimal 

15 March 2000 Ref. 16


One problem that I have encountered, is being able to create your own customized colors for the ColorDialog component.
The custom colors are represented in the CustomColors-property and are written in hexadecimal.
But how do you convert a TColor representation into a hexadecimal representation?

You can now use the following function:

function ColorToHex(const AColor : integer) : string;

begin
  Result := IntToHex(AColor, 8);
end; {ColorToHex}

This function will convert a TColor representation (which is really an integer-type) into a hexadecimal representation, for example:

ColorDialog.CustomColors.Add('ColorA=' + ColorToHex(clBlue));

This will add Blue (clBlue) as a custom color to the color-dialog.


Back