Setting a value of a Tcolorbox ...

Hi Experts,

I trying to set a TColorBox with a value i have from the database.

Im using a TColorBox to set flags/reminders, The user selects the color and it gets saved to the database. Example its its 'clLime' the colour that has been selected all im storing is 'Lime'. Or should i store the whole value in the database.

The problem im having its getting the value from the database and setting the value back to the TColourBox


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dagan HooverDeveloperCommented:
Save it to the data base like so:


Retreive and set like so:

ColorBox1.Selected := TColor(StrToInt(DataBaseReturn));

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I usually store it as a string value. example

mytable.fieldbyname('selcolor').asstring = ColorToString(colorbox.selected) ;

Showing from database
colorbox.selected := StringToColor(mytable.fieldbyname('selcolor').asstring) ;
Sorry ThievingSix, usually do a refresh before posting. Forgot this time...
Pretty much the same answer I guess.
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Dagan HooverDeveloperCommented:
Don't worry about it, he might want to have the colors readable from the database.
My suggustion is save as integer in database.

if you want to display color name then use ColorToString()  function
The problem is that with RGB colors you aren't limited to clLime clRed etc, you can have hex values for any colour. For this reason, store as an integer, not a string, otherwise your database might look like this:

...and now when you convert it back you now have to detect what is a string, and what is a hex value.

So make sure that all the data is of a uniform type.
"...and now when you convert it back you now have to detect what is a string, and what is a hex value."
Not if you use StringToColor, ColorToString; It handles that for you.
I like using string purely because at a quick glance I can see what most colours I have on offer are being used.
Forced accept.

EE Admin
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.