Re: getSelf() doesn't work in onOpen

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hi Thomas,

----- Original Message -----
From: "Thomas Parslow (PatRat)" <patrat at rat-software.com>
> Got a problem with a program using win32lib, in the onOpen event when
> i call getSelf() it always seems to return 0, is there a way this can be
> fixed?

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."

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu