RE: Re[2]: getSelf() doesn't work in onOpen
- Posted by Derek Parnell <ddparnell at bigpond.com> Apr 11, 2001
- 399 views
Okay, I assumed that only the main window was giving us trouble, but you have correctly highlighted a more general bug. Any place in which a user-defined event handler can be called, that is itself called from a routine that was not invoked due a Windows message, needs special handling for getSelf() to work. Your fix only does part of the job. The proper way is to do this ... pushSelf(id) invokeHandler(id, ...) VOID = popSelf() that is to say, if you use pushSelf() you also need to match it with a popSelf() call. Of course the simple way to fix this, even if it is overkill, is to embed the push/pop in the invokeHandler() routine. ----------- cheers, Derek Parnell > -----Original Message----- > From: Thomas Parslow (PatRat) [mailto:patrat at rat-software.com] > Sent: Thursday, 12 April 2001 8:52 AM > To: EUforum > Subject: Re[2]: getSelf() doesn't work in onOpen > > > > > > you have found a bug. > > > > There are two workarounds. > > > > a) Instead of using onOpen[xx] use setHandler(). > > > > setHandler( mywin, w32HOpen, routine_id("mywin_open")) > > > > if you do this the parameters of the handler procedure must be... > > procedure mywin_open(integer self, integer event, sequence parms) > > > > and you don't have to call getSelf() as the 'self' > parameter is supplied. > > > > b) Change win32lib.ew. > > Find the line ... > > mainWindow = id > > in the WinMain() procedure and insert after that ... > > pushSelf(id) > > > > Now getSelf() should work. > > > > The reason is that getSelf() was designed to be used by > handlers that got > > invoked as a response to a Windows message. But at the time > of opening the > > very first window, which is done in WinMain, there has been > no Windows > > messages yet so the internal stack of control ids is empty. > The fix to > > win32lib.ew just preloads the stack with the initial window's id. > > > > The setHandler() function doesn't use the internal id > stack, so that's why > > it works. > > > > ------ > > Derek Parnell > > Melbourne, Australia > > "To finish a job quickly, go slower." > > Hi, > This didn't fix the problem, it was happening when I was opening <snip> > > >