Event handler questions

  1. If I add an event handler to a control, but do not put any actual code in it, is that equivalent to having no event handler at all (apart perhaps from a few cycles wasted in calling it)? Or are there hidden side effects?

  2. Some event handlers want to return a Boolean. What happens if the hanlder returns neither? Is that the same as False, or True, or neither?

Returning a value is like any other function so if you don’t have a Return in your code it will be the default for the data type (false for boolean).

Not implementing an event handler will be the equivalent of not returning a specific value if you did implement the event handler.

So putting an #if#endif around the entire content of an event handler should be the same as not implementing the handler, in the case where the #if condition is not met.

Never tried it but I would assume so.

I can’t say I agree with kevin’s assumption. (not that I have anything more than an assumption!)

I discovered from a Windows HTMLViewer bug, that if you add an event handler the compiler can “see it” even if it’s totally empty. This actually caused a problem with what I was doing, even though the Event Handler was empty.

I don’t know the technical details, but adding the empty event handler would make things stop working, removing it would restore functionality.

Well of course it would be a Windows DesktopHTMLViewer. That’s where all this is leading. I may have a situation where a KeyDown handler works well enough in macOS, but unchanged causes a DesktopHTMLViewer in Linux to “not see” a number of characters, such as backspce, delete, Return/Enter, and the arrow keys. So in that specific instance for Linux I have the handler return early. For WIndows, however, with the same keys not seen, I have to put the #ifdef (as mentioned earlier) around the whole handler for Windows, when the HTMLViewer sees most of the missing keys but still not the arrow keys.

I suppose there’s no way to have a particular event handler only for specific desktop platforms, is there?

Mine was adding JavascriptRequest even if totally empty caused the HTMLViewer not to store cookies. It has since been fixed.

I dunno what you can do besides file a ticket. If you have control over the contents, you could move key trapping to the HTML/JS and send the data to Xojo through JavascriptRequest.

Mmm. I haven’t yet pinned down precisely what’s happeneing. In addition, I’m testing this in VMs and so am using a macOS keyboard. Whether that has an impact is unclear. I’ll not get to test a Win version on a real Win-11 box until Monday.

Unfortunately that’s not the case. Just the fact that you’ve added it to the control will make the event handler exist and therefore get “called”.

Not anymore anyway. This behavior changed when the product transitioned to being Xojo.

Well I would expect that. AISB, however, is that functionally equivalent to having no event handler, except for the few cycles wasted making the call to th empty handler?

The best answer I can give you is “maybe”.

I know for instance that in some places in the web framework, the underlying behavior is different depending on whether the event is actually implemented or not. For instance not implementing and event means that the browser is told not to send those events at all in order to cut down on traffic over the wire. Otherwise there’d be messages sent and processed which were ultimately discarded. In that case, just blocking out the code would cause the app to actually do other things.