Bart Verbakel 3 Posted July 29, 2023 Hello all, I want to change to color of a combobox, depending of the contents of it. If CB1 and CB2 contain the same value, the color of CB1 will be orange, if not the color will be default (ClWindow) procedure TForm1.ComboBox1Change(Sender: TObject); var ClOrange:ColorRef; begin ClOrange:=RGB(255,160,0); if Combobox1.Text=Combobox2.Text then Combobox1.Color:=ClOrange else Combobox1.Color:=ClWindow; end; This code works OK, but I got a warning during compling: W1071 Implicit integer cast with potential data loss from 'Cardinal' to 'TColor' It feels like my code is not 100% correct , but I don't understand the issue. I tried conversions to RGB or a StringToColor conversion, but all in vain, How can I prevent this hint from popping up (and not disabeling it in the options 😉 ) With kind regards, Bart Share this post Link to post
PeterBelow 238 Posted July 29, 2023 1 hour ago, Bart Verbakel said: var ClOrange:ColorRef; Change that to Var clOrange: TColor; Share this post Link to post
Bart Verbakel 3 Posted July 29, 2023 Yes, that works ok for me. Thank you Share this post Link to post
Remy Lebeau 1393 Posted July 30, 2023 Alternatively, there are many color constants defined in the Vcl.Graphics and System.UITypes units. The Vcl.Graphics.clWebOrange constant maps to the System.UITypes.TColorRec.Orange constant, which has a numeric value of $00A5FF (ie, RGB(255, 165, 0)), which is almost identical to your desired RGB color. Share this post Link to post
Stefan Glienke 2002 Posted July 31, 2023 How would changing the variable from ColorRef to TColor help? That will only change the location of the warning because RGB returns ColorRef (given this is the function from Winapi.Windows.pas). Share this post Link to post