RGB TO HEX or COLOR TO HEX

Can some one write me a code for converting a hex value (#000000) for a color in a richedit to TColor (or whatever) so that I can do this:
ColorDialog1.Color:=Variable;

Comments

  • [b][red]This message was edited by zibadian at 2004-2-14 7:26:31[/red][/b][hr]
    : Can some one write me a code for converting a hex value (#000000) for a color in a richedit to TColor (or whatever) so that I can do this:
    : ColorDialog1.Color:=Variable;
    :
    A TColor is a subtype of an integer, so you can use the same functions for TColor variables as for integer variables. Here are two functions to convert hex values to integers:
    http://www.codepedia.com/1/HexToInt
    The reverse function already exists in Delphi.

  • The code you wrote works fine except when you try to convert this or some other hexs to integer.(FF8040) It took my attention that when the number starts with FF, I got a problem. Is the problem in your code or am I doing something wrong. Just to inform you: I use this to convert a web site color to delphi color. May the problem have anything to the with this?
  • : The code you wrote works fine except when you try to convert this or some other hexs to integer.(FF8040) It took my attention that when the number starts with FF, I got a problem. Is the problem in your code or am I doing something wrong. Just to inform you: I use this to convert a web site color to delphi color. May the problem have anything to the with this?
    :
    It can start with FF if the color has a lot of red in it, since Delphi colors are coded as AlphaRGB colors, where Alpha indicates if a color is a system-color or a RGB color. Each of these is a single byte, thus a color of FF8040 will be a kind of dark blue. See the help files of more info on the TColor coding.
  • : Can some one write me a code for converting a hex value (#000000) for a color in a richedit to TColor (or whatever) so that I can do this:
    : ColorDialog1.Color:=Variable;

    One of the first Delphi programs I wrote was a colour picker for web programmers. Since it was one of my first programs, it's not the greatest code, but you can download the program (which comes with source) here:

    http://hexcolour.mannsoft.ca/
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories