Hi,

Here is a python script that shows the problem in action.

By default the script raises an error when trying to retreave the 
offsetTop property. However, if you uncomment the commented line just 
before that, then it works.

Also, if using win32com.client.Dispatch instead of 
comtypes.client.CreateObject(...,dynamic=True) the script also works.

--Script--
import comtypes.client
print "starting IE... ",
appObj=comtypes.client.CreateObject('internetExplorer.Application',dynamic=True)
print appObj
appObj.Visible=True
print "Opening URL... ",
appObj.Navigate('about:blank')
print "done"
print "fetching text range for body... ",
range=appObj.Document.body.createTextRange()
#range=comtypes.client.dynamic._Dispatch(range._comobj)
print range
print "OffsetTop property: ",
offsetTop=range.offsetTop
print "%s"%offsetTop
--end of script --

Mick

On 16/01/2009 2:44 AM, Thomas Heller wrote:
> Michael Curran schrieb:
>    
>> Hi,
>>
>> I have been using comtypes 0.6 dynamic dispatch support with the MSHTML
>> interfaces in Internet Explorer and Outlook Express.
>>
>> I have noticed that for some reason, comtypes is unable to find some
>> properties, yet win32com can.
>>
>> Specifically, using a text range object retreaved by
>> IHTMLElement::createTextRange(), I can not access any properties that
>> exist on the IHTMLTextRangeMetrics interface.
>>
>> The text range object supports IHTMLTxtRange and IHTMLTextRangeMetrics,
>> I'm not sure about any other interfaces.
>>
>> I can access any property on the IHTMLTxtRange interface, but not
>> IHTMLTextRangeMetrics.
>>      
>
> Michael,
>
> can you please post some example code that does not work in comtypes
> but does work in pywin32?
>
>    
>> I have found a temporary solution to the problem, and that is:
>> * In clude a comtypes.client.dynamic._Dispatch instance on the
>> comtypes.client.lazybind.Dispatch instance, called something like
>> '_dispatch'.
>> *inlazybind.Dispatch.__bind: catch NameError as well as
>> comtypes.COMError when calling iTypeComp.bind.
>> *in lazybind.Dispatch.__getattr__: if a property can not be found with
>> __bind (descr is None), then return getattr(self._dispatch,name). This
>> will allow the name to be fetched using GetIDsOfNames etc.
>>
>> This solution fixes the problem for me, and I can now access some more
>> of the properties.
>>
>> I have no idea why ITypeComp.bind cannot find the properties.
>>
>> Interested if anyone has any idea why this might occure, or whether this
>> solution is appropriate.
>>      
>
>
>    

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users

Reply via email to