pythoncom and IDispatch

Roger Upole rupole at hotmail.com
Wed May 17 00:23:26 EDT 2006


"fraca7" <fraca7 at free.fr> wrote in message news:44688c2a$0$7047$636a55ce at news.free.fr...
> Hello. I got a little problem while using pythoncom to automate IE; for some reason, changing the 'selectedIndex' on an 
> instance of IHTMLSelectElement doesn't fire the 'onchange' event (I guess this is a bug in mshtml).

As I understand it, this was done as a security measure to foil script
exploits.

> So, I tried to get the 'onchange' event handler and call it myself. According to the docs, this is a simple IDispatch 
> implementation and calling Invoke() should do the trick; I actually have a working example of this in Delphi.
>
> But I can't manage to get it work in Python; the following code
>
>
>         idisp = pythoncom.WrapObject(elt.onchange)
>         idisp.Invoke(pythoncom.DISPID_VALUE,
>                      0x400, # LOCALE_USER_DEFAULT
>                      pythoncom.DISPATCH_METHOD,
>                      False)
>
> fails with an AttributeError:
>

You can access the underlying IDispatch using the
_oleobj_ property, ie elt.onchange._oleobj_.Invoke(......)

Alternately, you can also use FireEvent, which would look
something like this (untested):
elt.FireEvent('onchange',elt.onchange)


           Roger



----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----



More information about the Python-list mailing list