[python-win32] return of by reference parameters in event handlers works not like expected

Moore, Paul Paul.Moore@atosorigin.com
Thu, 21 Nov 2002 15:00:46 -0000


From: heo@propack-data.com [mailto:heo@propack-data.com]
> somehow I am not able to change by reference parameters in an event
> handler.
>=20
> I don't think it's a big thing, but I don't see the trick...maybe =
someone
> can tell me what's going wrong...

What you do is to return a tuple consisting of the return value, =
followed by
the value you want to set for any "out" (ByRef) parameters. Here's an
example using a simple component (WScriptEx). The Sleep method sleeps,
firing OnTick events based on the second parameter - OnTick takes a =
ByVal
Remaining parameter (how long remaining) and a ByRef WakeUp parameter =
(set
to True to wake up). The "return 0,1" means to return 0 as the return =
value
for the event handler, and set WakeUp to 1.

You need to return N+1 values, where N is the number of ByRef parameters =
- ie,
you need to return the ones you *don't* change, not just the ones you =
do...

Hope this helps,
Paul.

import win32com.client

class wexEvents:
    def OnBreak(self, *args):
        wex.WakeUp()
    def OnWakeUp(self, *args):
        print "WakeUp", `args`
    def OnTick(self, Remaining, WakeUp):
        print "Tick...", Remaining, `WakeUp`
        if Remaining < 8000:
            return 0, 1

wex =3D win32com.client.DispatchWithEvents("WshToolbox.WScriptEx", =
wexEvents)

wex.Sleep(10000,1000)