Re: win32lib event handling question
- Posted by Derek Parnell <ddparnell at bigpond.com> Jul 20, 2005
- 478 views
ags wrote: > > Derek Parnell wrote: > > My argument now is that we should compromise. As routine_id() is a special > > usage technique, > > and not one used in common code, it should be allowed to reference routines > > further > > down in the source code, but direct references should still stick with the > > RDS philosophy. > > People who are coding are smart enough to not be confused by this. > > I think at least a warning of a forward routine_id reference would give you > the chance to think about other ways of doing it (if possible). Then again > maybe we should be checking that routine_id(...) doesn't = -1? > eg > > }}} <eucode> > -- in include file > include win32lib.ew > > procedure bad_routine_id() > puts(1, "Warning: Bad routine_id used. Check for forward reference\n") > -- and "Sorry but I can't tell you where it is" > end procedure > global constant rid_Bad_routine = routine_id("bad_routine_id") > > global function safe_routine_id(sequence code_name) > return w32iff(routine_id(code_name), routine_id(code_name), > rid_Bad_routine) > -- that's if -1 is false? otherwise if.. then.. > end function > > -- in code > procedure Window1_onMouse() > VOID = message_box("The mouse moved!!", "Important", MB_OK) > end procedure > setHandler(Button1, w32HMouse, safe_routine_id("Window1_onMouse") ) > <font color="#330033"></eucode> {{{ </font> > > And with safe_routine_id() in an early included header most functions > /procedures would be visible anyway wouldn't they? Actually that turns out not to be the case. When the routine_id() is executed, the string passed to it will be the name of a routine that occurs further down in the source code and thus invisible to routine_id. The way to deal with this is convoluted and totally obtuse ...
-- in code global atom rid_safe_routine_id include win32lib.ew procedure Window1_onMouse() VOID = message_box("The mouse moved!!", "Important", MB_OK) end procedure setHandler(Button1, w32HMouse, call_func(rid_safe_routine_id,{"Window1_onMouse"}) ) include saferid.e -- *MUST* be and the end of the main code file.
The content of saferid.e would be like ...
procedure bad_routine_id() puts(1, "Warning: Bad routine_id used. Check for forward reference\n") -- and "Sorry but I can't tell you where it is" end procedure global constant rid_Bad_routine = routine_id("bad_routine_id") global function safe_routine_id(sequence code_name) return w32iff(routine_id(code_name), routine_id(code_name), rid_Bad_routine) -- that's if -1 is false? otherwise if.. then.. end function rid_safe_routine_id = routine_id("safe_routine_id")
Its the physical order of the lines of code that matters, and not which order they are executed in. -- Derek Parnell Melbourne, Australia Skype name: derek.j.parnell