How can I convert TColor to html-color in Delphi

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:

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:

This will set the MyHTMLColor variable to the string ‘#FF0000’, which is the HTML color code for red.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *