1. what's the difference
- Posted by don cole <doncole at pacbell.net> Jun 07, 2004
- 442 views
What is the difference between: onClick[PushButtonXX]=routine_id("whatever") and setHandler(PushButtonXX,w32HClick,routine_id("whatever"))
2. Re: what's the difference
- Posted by Derek Parnell <ddparnell at bigpond.com> Jun 07, 2004
- 427 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
3. Re: what's the difference
- Posted by don cole <doncole at pacbell.net> Jun 07, 2004
- 463 views
I see . I tried onClick[{PushButton1,PushButton2,PushButton3}]=routine_id("whatever") but of course it didn't work. I preferred the onClick way because I didn't like typing in all that (integer self,integer event,sequence parms)stuff. I just now figured out what the self is for. >From now on I am going to use the setHandle way. Anyway you cleared a lot up for me; thank you for your help.