Convert text to colourcode ? lazarus / 21-General ---------------------------------------------------------------------- majid.ebru · 2025-01-06 09:20 Hi Sorry , I have a beginner question   How can I convert "clMaron" to its code, $000080? Thanks ---------------------------------------------------------------------- Fibonacci · 2025-01-06 09:27 Graphics unit Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function ColorToString(Color: TColor): AnsiString;function StringToColor(const S: shortstring): TColor;function StringToColorDef(const S: shortstring; const DefaultValue: TColor): TColor; ---------------------------------------------------------------------- majid.ebru · 2025-01-06 10:14 Quote from: Fibonacci on January 06, 2025, 10:27:56 amGraphics unit Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function ColorToString(Color: TColor): AnsiString;function StringToColor(const S: shortstring): TColor;function StringToColorDef(const S: shortstring; const DefaultValue: TColor): TColor; Have you used these commands you mentioned? These commands do not give the desired output. ---------------------------------------------------------------------- Fibonacci · 2025-01-06 10:16 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses SysUtils, Graphics; begin  WriteLn(IntToHex(StringToColor('clMaroon')));  WriteLn(IntToHex(StringToColor('clRed')));  ReadLn;end. 00000080 000000FF ---------------------------------------------------------------------- TRon · 2025-01-06 10:21 As shown by Fibonacci TColor is just a hex value. clXXX is just a fancy (constant) name representing that hex value and which can also be expressed as a string to convert to a hex-value. See also wiki ---------------------------------------------------------------------- dsiders · 2025-01-06 10:57 Quote from: TRon on January 06, 2025, 11:21:17 amAs shown by Fibonacci TColor is just a hex value. clXXX is just a fancy (constant) name representing that hex value and which can also be expressed as a string to convert to a hex-value. See also wiki The part that is not obvious is that ColorToString() returns the name for the color constant instead of its value. clRed returns 'clRed' - not '$000000FF'. ---------------------------------------------------------------------- Fibonacci · 2025-01-06 10:58 Quote from: dsiders on January 06, 2025, 11:57:36 amThe part that is not obvious is that ColorToString() returns the name for the color constant instead of its value. clRed returns 'clRed' - not '$000000FF'. Use StringToColor then ---------------------------------------------------------------------- dsiders · 2025-01-06 11:06 Quote from: Fibonacci on January 06, 2025, 11:58:57 amQuote from: dsiders on January 06, 2025, 11:57:36 amThe part that is not obvious is that ColorToString() returns the name for the color constant instead of its value. clRed returns 'clRed' - not '$000000FF'. Use StringToColor then Okay. But ColorToString(StringToColor('$000000FF')) still returns 'clRed'. ---------------------------------------------------------------------- wp · 2025-01-06 11:22 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  Graphics; function ColorToStr(AColor: TColor): String;var  r,g,b: Byte;begin  RedGreenBlue(ColorToRGB(AColor), r, g, b);  Result := Format('$%.2x%.2x%.2x', [b, g, r]);end; ---------------------------------------------------------------------- majid.ebru · 2025-01-06 11:49 Quote from: wp on January 06, 2025, 12:22:11 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  Graphics; function ColorToStr(AColor: TColor): String;var  r,g,b: Byte;begin  RedGreenBlue(ColorToRGB(AColor), r, g, b);  Result := Format('$%.2x%.2x%.2x', [b, g, r]);end; Thank you ---------------------------------------------------------------------- Fibonacci · 2025-01-06 11:53 Quote from: dsiders on January 06, 2025, 12:06:35 pmQuote from: Fibonacci on January 06, 2025, 11:58:57 amQuote from: dsiders on January 06, 2025, 11:57:36 amThe part that is not obvious is that ColorToString() returns the name for the color constant instead of its value. clRed returns 'clRed' - not '$000000FF'. Use StringToColor then Okay. But ColorToString(StringToColor('$000000FF')) still returns 'clRed'.  Yes, so? ColorToString($FF) = clRed, what else would it be? Hex? Then use IntToHex, maybe '$'+IntToHex(color, 6) ---------------------------------------------------------------------- dsiders · 2025-01-06 12:16 Quote from: Fibonacci on January 06, 2025, 12:53:23 pmQuote from: dsiders on January 06, 2025, 12:06:35 pmQuote from: Fibonacci on January 06, 2025, 11:58:57 amQuote from: dsiders on January 06, 2025, 11:57:36 amThe part that is not obvious is that ColorToString() returns the name for the color constant instead of its value. clRed returns 'clRed' - not '$000000FF'. Use StringToColor then I guess you missed my point entirely. Nevermind. Flail away. Okay. But ColorToString(StringToColor('$000000FF')) still returns 'clRed'.  Yes, so? ColorToString($FF) = clRed, what else would it be? Hex? Then use IntToHex, maybe '$'+IntToHex(color, 6) ---------------------------------------------------------------------- Fibonacci · 2025-01-06 12:37 Quote from: dsiders on January 06, 2025, 01:16:02 pmQuote from: Fibonacci on January 06, 2025, 12:53:23 pmQuote from: dsiders on January 06, 2025, 12:06:35 pmQuote from: Fibonacci on January 06, 2025, 11:58:57 amQuote from: dsiders on January 06, 2025, 11:57:36 amThe part that is not obvious is that ColorToString() returns the name for the color constant instead of its value. clRed returns 'clRed' - not '$000000FF'. Use StringToColor then I guess you missed my point entirely. Nevermind. Flail away. Okay. But ColorToString(StringToColor('$000000FF')) still returns 'clRed'.  Yes, so? ColorToString($FF) = clRed, what else would it be? Hex? Then use IntToHex, maybe '$'+IntToHex(color, 6) You are telling me to 'flail away' while struggling with even posting a simple reply properly... Its not easy to get your point. ---------------------------------------------------------------------- Thaddy · 2025-01-06 13:10 color asked for is clMaroon...not red... ---------------------------------------------------------------------- Aruna · 2025-01-06 20:15 Quote from: majid.ebru on January 06, 2025, 10:20:02 amHi Sorry , I have a beginner question   How can I convert "clMaron" to its code, $000080? Thanks Hello @majid.ebru. I have attached a zip that has the source code for what you want to do. Once you have the program running please click the 'select color' button which will pop-up a color dialogue then choose maroon (or any color you wish to know the $code for) click 'OK' and the form caption will show you the $code for the color you have selected. In the attached screenshot the color selected was Maroon. ---------------------------------------------------------------------- Joanna · 2025-01-06 23:48 Quote from: wp on January 06, 2025, 12:22:11 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  Graphics; function ColorToStr(AColor: TColor): String;var  r,g,b: Byte;begin  RedGreenBlue(ColorToRGB(AColor), r, g, b);  Result := Format('$%.2x%.2x%.2x', [b, g, r]);end; I don’t really understand the meaning of the $%.2x%.2x%.2x' ---------------------------------------------------------------------- wp · 2025-01-07 00:12 Quote from: Joanna from IRC on January 07, 2025, 12:48:10 amQuote from: wp on January 06, 2025, 12:22:11 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  Graphics; function ColorToStr(AColor: TColor): String;var  r,g,b: Byte;begin  RedGreenBlue(ColorToRGB(AColor), r, g, b);  Result := Format('$%.2x%.2x%.2x', [b, g, r]);end; I don’t really understand the meaning of the $%.2x%.2x%.2x'  https://www.freepascal.org/docs-html/rtl/sysutils/format.html %x --> hexadecimal format %.2x --> hexadecimal format with two digits, add '0' if value > 9 $ --> no special meaning, just insert this in the output string literally ---------------------------------------------------------------------- dseligo · 2025-01-07 02:30 Quote from: wp on January 07, 2025, 01:12:14 am%.2x --> hexadecimal format with two digits, add '0' if value > 9 add '0' if value <= F ---------------------------------------------------------------------- wp · 2025-01-07 10:19 Quote from: dseligo on January 07, 2025, 03:30:55 amQuote from: wp on January 07, 2025, 01:12:14 am%.2x --> hexadecimal format with two digits, add '0' if value > 9 add '0' if value <= F You are right: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1;uses  SysUtils;begin  WriteLn(Format('%x', [$F]));        // --> F  WriteLn(Format('%.2x', [$F]));      // --> 0F  WriteLn(Format('%x', [$10]));        // --> 10  WriteLn(Format('%.2x', [$10]));      // --> 10  ReadLn;end. ---------------------------------------------------------------------- Joanna · 2025-01-07 12:03 Thanks wp Ive never used format much so didn’t know the details