Re: what's the difference
- Posted by Derek Parnell <ddparnell at bigpond.com> Jun 07, 2004
- 425 views
don cole wrote: > > > What is the difference between: > onClick[PushButtonXX]=routine_id("whatever") > and > setHandler(PushButtonXX,w32HClick,routine_id("whatever")) The onXXX[] method is going away soon, so don't get too 'hooked' on it. The difference is that the onXXX is a global variable that any part of your code, or someone else's library, can write to. This means that you can accidently create bugs that are difficult to find, just by incorrectly changing an element in the variable or even the whole thing. The setHandler() method is a procedure call. This means that Win32lib can validate your parameters and catch many of these errors. It also allows the library to easily implement chained handlers. For example, If you code has ... setHandler(NameFld,w32HKeyPress,routine_id("register_change")) setHandler(NameFld,w32HKeyPress,routine_id("validatename")) setHandler(AddressFld,w32HKeyPress,routine_id("register_change")) setHandler(AddressFld,w32HKeyPress,routine_id("validateaddr")) it sets up a chain of handlers in which "register_change" is called first, then appropriate 'validation' code is called. This is also VERY useful for people who are writing add-on libraries. The setHandler() method can save keystrokes too, in the situations where you are sharing handler code with a number of controls. setHandler( {PushButtonXXX, PushButtonYYY}, w32HClick,routine_id("whatever")) or even having common-ish code for different events... setHandler( PushButtonXXX, {w32HClick, w32HKeyDown},routine_id("whatever")) As a side effect of setHandler(), the library has standardized on the calling signature of your handler code. Every handler routine always receives three parameters. With the onXXX[] method, the number of parameters depended on the type of event being invoked. This made it hard to write generic code. It is also easier now to add new information to be passed to handlers without breaking existing code. -- Derek Parnell Melbourne, Australia