Re: win32lib: Scope of event handlers?
- Posted by David Cuny <dcuny at LANSET.COM> Aug 15, 2000
- 436 views
John Coonrod wrote: > It appears that setting onClick must not be > done inside a procedure. Is that true? No, you can set the code anywhere. It's just simple variable assignment. More likely, the scope of routine_id is causing you grief. Remember that routine_id can only be called *after* the routine is defined. You probably did something like this: onClick[me] = routine_id("foo") procedure foo( ... ) and onClick[me] was set to -1. By moving the assignment, you probably moved routine_id after the routine: procedure_foo( ... ) onClick[me] = routine_id("foo") and things started working again. Perhaps I should have written wrappers like this: procedure OnClick( integer id, integer callback ) if callback = -1 then abortErr("OnClick: Routine not defined") else onClick[id] = routine end if end procedure This would save people from a lot of grief by giving a warning, although writing: OnClick( me, routine_id("foo") ) is still a bit awkward. I *really* wish I could write: procedure OnClick( integer id, sequence routine ) callback = routine_id(routine) if callback = -1 then abortErr("OnClick: Routine " & routine & " not defined") else onClick[id] = routine end if end procedure and then you coule write: OnClick( me, "foo" ) but I can't, because of the scoping issues with routine_id. Namely, if you use this routine, you can only pass it routines that have been defined *before* this routine was defined. *grumble* -- David Cuny