1

I am trying to store the ComboColorBox.Color property in a database field through LiveBindings in a Firemonkey Project. I want to store the hexadecimal AlphaColor value, but the hex color value is automatically converted to a decimal value and not an AlphaColor.

I've searching in the LiveBindings documentation and found that I can change the value of control property before is stored in database writing a binding expression in CustomParse property of the Binding. The problem is that there is no built in function to convert an AlphaColor to a String in an expression.

Do I have to write a custom function to do that? How do I write that function and where? Or there is another solution?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Eratsu
  • 21
  • 6
  • There's an example of using color values with livebindings, here: http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Tutorial:_Using_TPrototypeBindSource_and_the_LiveBindings_Designer – Dave Nottage Mar 06 '18 at 02:38

1 Answers1

1

You should know that a TAlphaColor is an integer, or more precisley a cardinal as defined in System.UITypes

type TAlphaColor = Cardinal;

Thus you can apply any integer to string conversion functions, like:

Label1.Text := IntToStr((Sender as TComboColorBox).Color);    // decimal notation
Label2.Text := IntToHex((Sender as TComboColorBox).Color, 8); // hexadecimal notation

So, to store the TAlphaColor value as a hexadecimal string, you would convert the color value using IntToHex(). On the other hand, Are you sure you really want to store it in the db as a string in the first place.

Tom Brunberg
  • 20,312
  • 8
  • 37
  • 54