Here is a function that you can use to convert a TColor value to a string representation of the corresponding HTML color code in Delphi:
1 2 3 4 |
function TColorToHTMLColor(Color: TColor): string; begin Result := ‘#’ + IntToHex(Color and $00FFFFFF, 6); end; |
This function works by first masking off the high byte of the TColor value, which contains the alpha channel information. The resulting integer is then passed to the IntToHex function, which converts it to a hexadecimal string. Finally, the string is prefixed with a ‘#’ character to create the full HTML color code.
You can use this function in your Delphi code like this:
1 |
MyHTMLColor := TColorToHTMLColor(clRed); |
This will set the MyHTMLColor
variable to the string ‘#FF0000’, which is the HTML color code for red.
Leave a Reply