Re: Unexplainable behavior
- Posted by CChris <christian.cuvier at agriculture?gouv.?r> Jan 29, 2008
- 732 views
Mike777 wrote: > > I'm posting this follow up under a new subject because I'm at my wits end on > this and would like somebody (anybody?) to take another look to see if > anything > pops out. > > I have a handler for a checkbox onClick event that I want to fire when the > user > clicks on a label to the left of the checkbox. I would presume this is fairly > common behaviour. > > I programmed an invokeHandler command into the onClick event of the label and > it certainly invokes the checkbox onClick handler when the label is clicked. > > But there is a problem in that it appears to actually invoke the handler twice > when running at "full speed". If it is slowed down by way of a sleep(1) > command > or insertion of a message_box, either in the label's onClick or anywhere > downstream > in the checkbox's onClick procedure it runs only once. > > My label click procedure now looks like this: > > procedure lblchkMyCheck_onClick (integer self, integer event, sequence params) > atom myAtom > setCheck(chkMyCheck,not(isChecked(chkMyCheck))) > sleep( 1) > myAtom = invokeHandler(chkMyCheck,w32HClick,{}) > end procedure > > My checkbox handler does a lot of things, one of which is to repaint virtually > every control on the screen (if that matters), along with present the results > of a calculation in a textbox (just one of many controls on the screen). > > If I pull out the sleep(1) line, then the system does something that seems > like > there is a bit of code somewhere I've forgotten about (which I generally refer > to as a poltergeist), because the above code runs twice, the first time with > the value of chkMyCheck appropriately changed from what it started out as and > the second time with the opposite. That is, the second time it is run with > the value of chkMyCheck exactly as chkMyCheck started, thereby putting a > result > on the screen which is the same as when I started (obviously a bit > unproductive, > complete with the check mark appearing for an instant and then resetting > itself > back to how it started. > > If I insert any CPU halting mechanism at any point in time (a sleep command, > or a message box) then the second execution is not done, the check box is > appropriately > changed only once and the value displayed in the textbox is the correct > (updated) > value. > > As another hint as to what is going on, if I remove the sleep and message box > commands, I can still get it to work, if I click on the label and hold down > the left click button for a full second before letting it up. > > I could understand how holding the left click button down might cause the > event > to be registered twice, but this is the exact opposite. By clicking quickly > and lightly it executes twice. By clicking once (very slowly and heavily) it > only executes once. Baffling to me. > > If that is enough information to trigger somebody's (terrible) memory of > something > similar I'd love to hear about it. > > Thanks > > Mike 1/ add a ?123 somewhere in what you expect to be your only handler for the ckeckbox, and unambiguously determine whether it is run once or twice. 2/ If you get two of them, then search your entire project for the name of the supposedly unique handler. That will point you to the place(s) where it is called while you had forgotten about it. 3/ If you get only one of them, call getHandler(chkMyCheck,w32HClick), getHandler(Screen,w32HClick) and determine whether two or more pieces of code toggle the check box. 4/ create, outside IDE, a very basic window, a very basic w32HClick handler for it, and see what happens when you click the window. Perhaps your mouse is sending things it shouldn't, and you'll see it that way. Actually I'd start with 4/. CChris