[Solved] OnChange with TComboBox does not react on value changes by code lazarus / 31-LCL ---------------------------------------------------------------------- Murray_B · 2017-06-15 12:41 Hi! I have a form which shows a calendar entry. There is a TComboBox for reminder which activates or deactivates a TDateTimePicker: "No remind" => no TDateTimePicker, "Remind"=>show TDateTimePicker. The OnChange- Event works great if I switch it manually. If I try to edit an existing calendar entry and fill the TComboBox with the existing value, Ihave to call the OnChange event after that, otherwise it won't show my TDateTimePicker. What did I wrong? I am using lazarus-gtk2 with linux. Thanks in advance! ---------------------------------------------------------------------- Handoko · 2017-06-15 12:46 Hello Murray_B, Welcome to the forum. Can you please provide the code, compress all those files (not the exe and lib folder) and send the zip file to this forum? Usually when code is provided, it will get more responses. ---------------------------------------------------------------------- Murray_B · 2017-06-15 13:43 Thanks for the welcome, I'll try to add some more informations: You can download the source at http://www.thschuetz.de/temp/LOrga- Source.zip I am using Lazarus 1.6.4 If you start the application and press on "Termin anzeigen" (="show event", german app, sorry) you get a small window with the calendar entry. In the middle is a label "Erinnerung" (="Reminder") and a TComboBox "Benutzerdefiniert" ("user defined") After "Benutzerdefiniert" should be a TDateTimePicker, which is enabled by TFcaldata.EditRemindChange (line 358-362 in ucaldata.pas), but the event does not occur. I'll do the following to make the event happen: EditRemind.ItemIndex:=0;  // reset reminder TComboBox to "no remind" in line 680 EditRemind.ItemIndex:=Tcalevent(eventlist[currentevent]).remtype; // put the right data into it, 1 in this example for "user defined" => line 738 self.Showmodal();   // show the form If I understood right, there is a change in the second command (maybe in the first one too, doesn't matter) and this should call EditRemindChange to make some more fields visible/editable. The same problem occurs with the top left TComboBox "Termin"/"Aufgabe" (= appointment or todo entry). Can anybody help and tell me what I did wrong? ---------------------------------------------------------------------- Remy Lebeau · 2017-06-15 19:15 Quote from: Murray_B on June 15, 2017, 02:41:43 pmWhat did I wrong? Nothing at all.  The TComboBox.OnChange event is only fired when the *user* makes changes, not when the *code* makes changes.  This is documented behavior: QuoteThis event covers only changes made by the user, not by code. Note that this differs from how other OnChange events work, for example TEdit.OnChange is triggered by code text changes. This event is also triggered when the selection is changed by using the combo box list. Delphi does the same thing: QuoteNote: OnChange only occurs in response to user actions. Changing the Text property programmatically does not trigger an OnChange event. ---------------------------------------------------------------------- Murray_B · 2017-06-15 21:13 Ah, okay, thank you very much! It didn't come to my mind that there could be a special behaviour in TComboBox for this. I will keep it in mind for the next time, maybe there are similar "strange behaviours" anywhere else…