### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: Can we specify TColor using hex values?  (Read 2488 times)

#### Aruna

• Sr. Member
• Posts: 393
##### Can we specify TColor using hex values?
« on: August 24, 2024, 01:36:09 pm »
Hi, I have an array of colors.
Code: Pascal  [Select][+][-]
1. Colors: array[0..5] of TColor = (clRed, clOlive, clYellow, clGreen, clBlue, clPurple);
is it possible to specify the colors using hex ? For example can I use #FF0000 to specify the color red?
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

#### Aruna

• Sr. Member
• Posts: 393
##### Re: Can we specify TColor using hex values?
« Reply #1 on: August 24, 2024, 02:39:57 pm »
Please disregards the previous question. I found the answer in graphics.pp under the standard colors section. For anyone interested, here's how it can be done:
Code: Pascal  [Select][+][-]
1. clRed     = TColor(\$0000FF);

Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

#### paweld

• Hero Member
• Posts: 1187
##### Re: Can we specify TColor using hex values?
« Reply #2 on: August 24, 2024, 02:41:51 pm »
Yes, only the colors are stored in BGR format
Code: Pascal  [Select][+][-]
1. Colors: array[0..5] of TColor = (\$0000FF {clRed}, \$008080 {clOlive}, \$00FFFF {clYellow}, \$008000 {clGreen}, \$FF0000 {clBlue}, \$800080 {clPurple});
Best regards / Pozdrawiam
paweld

#### Aruna

• Sr. Member
• Posts: 393
##### Re: Can we specify TColor using hex values?
« Reply #3 on: August 24, 2024, 02:52:34 pm »
Yes, only the colors are stored in BGR format

Thank you, @paweld. I was wondering about why the usual RGB color components are represented in BGR order instead. Do you know why this approach was chosen? What are the advantages or benefits of using this format compared to the standard RGB format?
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

#### What I can do

• Jr. Member
• Posts: 87
##### Re: Can we specify TColor using hex values?
« Reply #4 on: August 24, 2024, 04:56:07 pm »
I don't know if you or anyone else would need this, but this is the collection from my Helper Database
This is some old stuff from my D6 enterprise days...

Code: Pascal  [Select][+][-]
1. TBrushStyle = (bsSolid, bsClear, bsHorizontal, bsVertical,
2.     bsFDiagonal, bsBDiagonal, bsCross, bsDiagCross);
3.
4. TPenStyle = (psSolid, psDash, psDot, psDashDot, psDashDotDot, psClear,
5.     psInsideFrame, psUserStyle, psAlternate);
6.
7. TPenMode = (
8. pmBlack, pmWhite,
9. pmNop, pmNot,
10. pmCopy, pmNotCopy,
11. pmMergePenNot, pmMaskPenNot,
12. pmMergeNotPen, pmMaskNotPen,
13. pmMerge, pmNotMerge,
14. pmMask, pmNotMask,
15. pmXor, pmNotXor);
16.
17.   clSystemColor = \$FF000000;
18.
19.   clScrollBar = TColor(clSystemColor or COLOR_SCROLLBAR);
20.   clBackground = TColor(clSystemColor or COLOR_BACKGROUND);
21.   clActiveCaption = TColor(clSystemColor or COLOR_ACTIVECAPTION);
22.   clInactiveCaption = TColor(clSystemColor or COLOR_INACTIVECAPTION);
23.   clMenu = TColor(clSystemColor or COLOR_MENU);
24.   clWindow = TColor(clSystemColor or COLOR_WINDOW);
25.   clWindowFrame = TColor(clSystemColor or COLOR_WINDOWFRAME);
26.   clMenuText = TColor(clSystemColor or COLOR_MENUTEXT);
27.   clWindowText = TColor(clSystemColor or COLOR_WINDOWTEXT);
28.   clCaptionText = TColor(clSystemColor or COLOR_CAPTIONTEXT);
29.   clActiveBorder = TColor(clSystemColor or COLOR_ACTIVEBORDER);
30.   clInactiveBorder = TColor(clSystemColor or COLOR_INACTIVEBORDER);
31.   clAppWorkSpace = TColor(clSystemColor or COLOR_APPWORKSPACE);
32.   clHighlight = TColor(clSystemColor or COLOR_HIGHLIGHT);
33.   clHighlightText = TColor(clSystemColor or COLOR_HIGHLIGHTTEXT);
34.   clBtnFace = TColor(clSystemColor or COLOR_BTNFACE);
35.   clBtnShadow = TColor(clSystemColor or COLOR_BTNSHADOW);
36.   clGrayText = TColor(clSystemColor or COLOR_GRAYTEXT);
37.   clBtnText = TColor(clSystemColor or COLOR_BTNTEXT);
38.   clInactiveCaptionText = TColor(clSystemColor or COLOR_INACTIVECAPTIONTEXT);
39.   clBtnHighlight = TColor(clSystemColor or COLOR_BTNHIGHLIGHT);
40.   cl3DDkShadow = TColor(clSystemColor or COLOR_3DDKSHADOW);
41.   cl3DLight = TColor(clSystemColor or COLOR_3DLIGHT);
42.   clInfoText = TColor(clSystemColor or COLOR_INFOTEXT);
43.   clInfoBk = TColor(clSystemColor or COLOR_INFOBK);
44.   clHotLight = TColor(clSystemColor or COLOR_HOTLIGHT);
45.   clGradientActiveCaption = TColor(clSystemColor or COLOR_GRADIENTACTIVECAPTION);
46.   clGradientInactiveCaption = TColor(clSystemColor or COLOR_GRADIENTINACTIVECAPTION);
47.   clMenuHighlight = TColor(clSystemColor or COLOR_MENUHILIGHT);
48.   clMenuBar = TColor(clSystemColor or COLOR_MENUBAR);
49.
50.   clBlack = TColor(\$000000);
51.   clMaroon = TColor(\$000080);
52.   clGreen = TColor(\$008000);
53.   clOlive = TColor(\$008080);
54.   clNavy = TColor(\$800000);
55.   clPurple = TColor(\$800080);
56.   clTeal = TColor(\$808000);
57.   clGray = TColor(\$808080);
58.   clSilver = TColor(\$C0C0C0);
59.   clRed = TColor(\$0000FF);
60.   clLime = TColor(\$00FF00);
61.   clYellow = TColor(\$00FFFF);
62.   clBlue = TColor(\$FF0000);
63.   clFuchsia = TColor(\$FF00FF);
64.   clAqua = TColor(\$FFFF00);
65.   clLtGray = TColor(\$C0C0C0);
66.   clDkGray = TColor(\$808080);
67.   clWhite = TColor(\$FFFFFF);
68.   StandardColorsCount = 16;
69.
70.   clMoneyGreen = TColor(\$C0DCC0);
71.   clSkyBlue = TColor(\$F0CAA6);
72.   clCream = TColor(\$F0FBFF);
73.   clMedGray = TColor(\$A4A0A0);
74.   ExtendedColorsCount = 4;
75.
76.   clNone = TColor(\$1FFFFFFF);
77.   clDefault = TColor(\$20000000);
78.
79.   { The following "cl" values come from the Web Named Color palette and
80.     are stored in the Windows COLORREF byte order x00bbggrr }
81.   clWebSnow = \$FAFAFF;
82.   clWebFloralWhite = \$F0FAFF;
83.   clWebLavenderBlush = \$F5F0FF;
84.   clWebOldLace = \$E6F5FD;
85.   clWebIvory = \$F0FFFF;
86.   clWebCornSilk = \$DCF8FF;
87.   clWebBeige = \$DCF5F5;
88.   clWebAntiqueWhite = \$D7EBFA;
89.   clWebWheat = \$B3DEF5;
90.   clWebAliceBlue = \$FFF8F0;
91.   clWebGhostWhite = \$FFF8F8;
92.   clWebLavender = \$FAE6E6;
93.   clWebSeashell = \$EEF5FF;
94.   clWebLightYellow = \$E0FFFF;
95.   clWebPapayaWhip = \$D5EFFF;
96.   clWebNavajoWhite = \$ADDEFF;
97.   clWebMoccasin = \$B5E4FF;
98.   clWebBurlywood = \$87B8DE;
99.   clWebAzure = \$FFFFF0;
100.   clWebMintcream = \$FAFFF5;
101.   clWebHoneydew = \$F0FFF0;
102.   clWebLinen = \$E6F0FA;
103.   clWebLemonChiffon = \$CDFAFF;
104.   clWebBlanchedAlmond = \$CDEBFF;
105.   clWebBisque = \$C4E4FF;
106.   clWebPeachPuff = \$B9DAFF;
107.   clWebTan = \$8CB4D2;
108.   // yellows/reds yellow -> rosybrown
109.   clWebYellow = \$00FFFF;
110.   clWebDarkOrange = \$008CFF;
111.   clWebRed = \$0000FF;
112.   clWebDarkRed = \$00008B;
113.   clWebMaroon = \$000080;
114.   clWebIndianRed = \$5C5CCD;
115.   clWebSalmon = \$7280FA;
116.   clWebCoral = \$507FFF;
117.   clWebGold = \$00D7FF;
118.   clWebTomato = \$4763FF;
119.   clWebCrimson = \$3C14DC;
120.   clWebBrown = \$2A2AA5;
121.   clWebChocolate = \$1E69D2;
122.   clWebSandyBrown = \$60A4F4;
123.   clWebLightSalmon = \$7AA0FF;
124.   clWebLightCoral = \$8080F0;
125.   clWebOrange = \$00A5FF;
126.   clWebOrangeRed = \$0045FF;
127.   clWebFirebrick = \$2222B2;
128.   clWebSaddleBrown = \$13458B;
129.   clWebSienna = \$2D52A0;
130.   clWebPeru = \$3F85CD;
131.   clWebDarkSalmon = \$7A96E9;
132.   clWebRosyBrown = \$8F8FBC;
133.   // greens palegoldenrod -> darkseagreen
134.   clWebPaleGoldenrod = \$AAE8EE;
135.   clWebLightGoldenrodYellow = \$D2FAFA;
136.   clWebOlive = \$008080;
137.   clWebForestGreen = \$228B22;
138.   clWebGreenYellow = \$2FFFAD;
139.   clWebChartreuse = \$00FF7F;
140.   clWebLightGreen = \$90EE90;
141.   clWebAquamarine = \$D4FF7F;
142.   clWebSeaGreen = \$578B2E;
143.   clWebGoldenRod = \$20A5DA;
144.   clWebKhaki = \$8CE6F0;
145.   clWebOliveDrab = \$238E6B;
146.   clWebGreen = \$008000;
147.   clWebYellowGreen = \$32CD9A;
148.   clWebLawnGreen = \$00FC7C;
149.   clWebPaleGreen = \$98FB98;
150.   clWebMediumAquamarine = \$AACD66;
151.   clWebMediumSeaGreen = \$71B33C;
152.   clWebDarkGoldenRod = \$0B86B8;
153.   clWebDarkKhaki = \$6BB7BD;
154.   clWebDarkOliveGreen = \$2F6B55;
155.   clWebDarkgreen = \$006400;
156.   clWebLimeGreen = \$32CD32;
157.   clWebLime = \$00FF00;
158.   clWebSpringGreen = \$7FFF00;
159.   clWebMediumSpringGreen = \$9AFA00;
160.   clWebDarkSeaGreen = \$8FBC8F;
161.   // greens/blues lightseagreen -> navy
162.   clWebLightSeaGreen = \$AAB220;
163.   clWebPaleTurquoise = \$EEEEAF;
164.   clWebLightCyan = \$FFFFE0;
165.   clWebLightBlue = \$E6D8AD;
166.   clWebLightSkyBlue = \$FACE87;
167.   clWebCornFlowerBlue = \$ED9564;
168.   clWebDarkBlue = \$8B0000;
169.   clWebIndigo = \$82004B;
170.   clWebMediumTurquoise = \$CCD148;
171.   clWebTurquoise = \$D0E040;
172.   clWebCyan = \$FFFF00; //   clWebAqua
173.   clWebAqua = \$FFFF00;
174.   clWebPowderBlue = \$E6E0B0;
175.   clWebSkyBlue = \$EBCE87;
176.   clWebRoyalBlue = \$E16941;
177.   clWebMediumBlue = \$CD0000;
178.   clWebMidnightBlue = \$701919;
179.   clWebDarkTurquoise = \$D1CE00;
180.   clWebCadetBlue = \$A09E5F;
181.   clWebDarkCyan = \$8B8B00;
182.   clWebTeal = \$808000;
183.   clWebDeepskyBlue = \$FFBF00;
184.   clWebDodgerBlue = \$FF901E;
185.   clWebBlue = \$FF0000;
186.   clWebNavy = \$800000;
187.   // violets/pinks darkviolet -> pink
188.   clWebDarkViolet = \$D30094;
189.   clWebDarkOrchid = \$CC3299;
190.   clWebMagenta = \$FF00FF; //   clWebFuchsia
191.   clWebFuchsia = \$FF00FF;
192.   clWebDarkMagenta = \$8B008B;
193.   clWebMediumVioletRed = \$8515C7;
194.   clWebPaleVioletRed = \$9370DB;
195.   clWebBlueViolet = \$E22B8A;
196.   clWebMediumOrchid = \$D355BA;
197.   clWebMediumPurple = \$DB7093;
198.   clWebPurple = \$800080;
199.   clWebDeepPink = \$9314FF;
200.   clWebLightPink = \$C1B6FF;
201.   clWebViolet = \$EE82EE;
202.   clWebOrchid = \$D670DA;
203.   clWebPlum = \$DDA0DD;
204.   clWebThistle = \$D8BFD8;
205.   clWebHotPink = \$B469FF;
206.   clWebPink = \$CBC0FF;
207.   // blue/gray/black lightsteelblue -> black
208.   clWebLightSteelBlue = \$DEC4B0;
209.   clWebMediumSlateBlue = \$EE687B;
210.   clWebLightSlateGray = \$998877;
211.   clWebWhite = \$FFFFFF;
212.   clWebLightgrey = \$D3D3D3;
213.   clWebGray = \$808080;
214.   clWebSteelBlue = \$B48246;
215.   clWebSlateBlue = \$CD5A6A;
216.   clWebSlateGray = \$908070;
217.   clCebWhiteSmoke = \$F5F5F5;
218.   clWebSilver = \$C0C0C0;
219.   clWebDimGray = \$696969;
220.   clWebMistyRose = \$E1E4FF;
221.   clWebDarkSlateBlue = \$8B3D48;
222.   clWebDarkSlategray = \$4F4F2F;
223.   clWebGainsboro = \$DCDCDC;
224.   clWebDarkGray = \$A9A9A9;
225.   clWebBlack = \$000000;
226.   WebColorsCount = 140;  { Two of which are duplicates Aqua/Cyan Fuchsia/Magenta }
227.

I figured anyone getting started or run across this post info might find it handy.

#### Aruna

• Sr. Member
• Posts: 393
##### Re: Can we specify TColor using hex values?
« Reply #5 on: August 24, 2024, 05:30:16 pm »
I don't know if you or anyone else would need this, but this is the collection from my Helper Database
This is some old stuff from my D6 enterprise days...
<snip>
I figured anyone getting started or run across this post info might find it handy.
This is useful. Thank you.
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

#### wizzwizz4

• New Member
• Posts: 10
##### Re: Can we specify TColor using hex values?
« Reply #6 on: August 24, 2024, 07:07:03 pm »
What are the advantages or benefits of using this format compared to the standard RGB format?

On a little-endian machine (which is most of them, these days), this format means that byte #0 is red, byte #1 is green, byte #2 is blue and – if present – byte #3 is alpha. This is a fairly standard format. It just so happens that we use big-endian notation for numbers in our source code, so it's written backwards there. The usual #FF0000 = red notation is mixed-endian, which Pascal has no special syntax for.

#### Aruna

• Sr. Member
• Posts: 393
##### Re: Can we specify TColor using hex values?
« Reply #7 on: August 25, 2024, 03:54:55 am »
What are the advantages or benefits of using this format compared to the standard RGB format?

On a little-endian machine (which is most of them, these days), this format means that byte #0 is red, byte #1 is green, byte #2 is blue and – if present – byte #3 is alpha. This is a fairly standard format. It just so happens that we use big-endian notation for numbers in our source code, so it's written backwards there. The usual #FF0000 = red notation is mixed-endian, which Pascal has no special syntax for.
Thank you @wizzwizz4 I am familiar with little endian and big endian. But this is the first time I have heard of mixed-endian.
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/