1. win32lib: Scope of event handlers?
- Posted by John Coonrod <jc at THP.ORG> Aug 15, 2000
- 435 views
I've moved some routines into an include file and find that they now do not work for reasons that are a mystery to me. One of the procedures creates a number of PushButtons, storing the handles in a sequence and setting onClick to another routine in the include file, using routine_id. It sets up the buttons just fine, but the onClick routines don't work. When the same code is in the main file, it seems to work just fine. The procedures are declared global. Any idea what the problem could be? ---------------- Dr. John Coonrod, Vice President, jc at thp.org The Hunger Project, 15 East 26th Street, NY, NY 10010 www.thp.org
2. Re: win32lib: Scope of event handlers?
- Posted by John Coonrod <jc at THP.ORG> Aug 15, 2000
- 438 views
I perhaps have figured this out. It appears that setting onClick must not be done inside a procedure. Is that true? When I moved all references to onClick outside routines, things were ok. ===== Original Message from Euphoria Programming for MS-DOS <EUPHORIA at LISTSERV.MUOHIO.EDU> at 8/15/00 7:12 am >I've moved some routines into an include file and find that they now do not >work for reasons that are a mystery to me. > >One of the procedures creates a number of PushButtons, storing the handles >in a sequence and setting onClick to another routine in the include file, >using routine_id. It sets up the buttons just fine, but the onClick routines >don't work. > >When the same code is in the main file, it seems to work just fine. The >procedures are declared global. > >Any idea what the problem could be? >
3. Re: win32lib: Scope of event handlers?
- Posted by David Cuny <dcuny at LANSET.COM> Aug 15, 2000
- 437 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