Spinedit event problem lazarus / 31-LCL ---------------------------------------------------------------------- ironphil · 2012-06-18 18:21 I am using several spinedit controls to transform some values from one format to another one and vice versa. So I can click in either group of spinedit controls to have the other group show the transformed value. This software was written a couple of years ago. I made some modifications to it recently and it seems the behaviour of the spinedit control has changed. I used to use the onchange event to trigger the calculation of the values and there was no problem. But now the software can enter into an infinite loop when doing so. I think the reason is because the onchange event is triggered whenever the value is changed, even if don't click the spinedit. The spinedit controls change the values of each other thus creating a large amount of onchange events (sometimes infinite or reaching the max/min values of the spinedit controls). I switch to using the onclick event instead which works great in linux (gtk) but not in windows. In windows, the onclick event is triggered only if I click in the number area of the spinedit, not when I click on the arrows. Is this normal? The oneditingdone event needs an additionnal click outside of the control to have it executed which is not what I want. I want the values to be calculated as soon as I click the arrows to change the values. Is there a way with the onchange event to make the difference between an onchange event from a click on the arrows and an onchange event from code? Maybe by using the focused property? Any other suggestion? ---------------------------------------------------------------------- KpjComp · 2012-06-18 22:35 Using OnChange is the correct way. All you need is an extra check to see if your update was GUI / or Calculated.  The way I do this is just keep a track of what I call the datachangecount, I basically increment when entering the procedure and decrement when exiting, so if the datachangecount = 1 , I know if it's GUI based update, otherwise it's an implicit OnChange from code. I've attached a example,  It's a simple currency converter for dollar,sterling & Euro.  Change one, and the other will change too. ---------------------------------------------------------------------- ironphil · 2012-06-18 23:04 Thanks, that is a nice way to do it as the same procedure is used for all the spinedit controls. I tried this: Code: [Select]if spinedit1.focus then [code to be executed]and it seems to work like I want since the control I click as the focus and not the other ones. But I had to code it for each spinedit controls. I should learn to use more of the Sender object properties. ---------------------------------------------------------------------- KpjComp · 2012-06-18 23:23 Checking the focus, is one way. The datachangecount method is a little bit more flexible though. eg. Say I wanted to set the Sterling to default to £100, you could alter the program like this -> Code: [Select]procedure TForm1.FormCreate(Sender: TObject); begin   sterlingToDollar := 1.56720;   sterlingToEuro := 1.24565;   //lets default to £100   eSterling.Value := 100;   eSterlingChange(eSterling); end;  In the FormCreate procedure, no control has focus so setting a default would be more tricky if your checking the focused property.  You can't even manually call SetFocus on your FormCreate either, as this will generate errors of not been able to focus a disabled window. Another flexibility example. I've found situations were I would like to do calculations that say are 2 levels deep, I could then check for datachangecount = 2; etc.