How to use the callback of COM objects

Gillou nospam at bigfoot.com
Wed Oct 3 10:25:38 EDT 2001


Hi,

I've tried this to provide a callback function to a COM object:
==============
import win32com.client
def HandleReadyState():
    # anything you want
    return
ox = win32com.client.Dispatch('MSXML.DomDocument')
ox.onreadystatechange = HandleReadyState
==============
And the last line raises this:
==============
Traceback (most recent call last):
  File "validation.py", line 7, in ?
    ox.onreadystatechange = HandleReadyState
  File "C:\Python21\win32com\client\dynamic.py", line 467, in __setattr__
    self._oleobj_.Invoke(self._olerepr_.propMapPut[attr].dispid, 0,
pythoncom.DI
SPATCH_PROPERTYPUT, 0, value)
TypeError: Objects of type 'function' can not be converted to a COM VARIANT
=============

This works perfectly when the equivalent is programmed in javascript.
"onreadystatechange" is an event that can be handled by a user function.

Did I miss something ?

Thanks in advance fo any hint.

--Gilles






More information about the Python-list mailing list