[python-win32] Re: problems in returning parameters using a COM client

George Vestergom unifoam@total.net
Fri, 20 Dec 2002 10:04:17 -0500


Don Dwiggins wrote:
> 
> Jens B Jorgensen writes:
> > Those parameters are most likely [in, out] params. This means you must pass
> > something in. Try:
> 
> > xpos, ypos = cd.GetPosition(0, 0)
> 
> Adding a bit to Jens' comments: [in, out] params need special treatment to
> avoid the need to modify a parameter in place.  Python's approach is to have
> you pass in the initial value, then get the updated value as part of the
> result (which will be a sequence, beginning with the COM object's return
> value, and containing all [in, out] and [out] params in left-to-right
> order).  For [out] params, it's a bit simpler: they'll just appear in the
> result sequence.
> 
> Also, a useful tool for working with COM components is Microsoft's OLE/COM Object
> Viewer (http://www.microsoft.com/com/resources/oleview.asp).
> 
> Enjoy,
> --
--------------------------------------

Much thanks to Don Dwiggins and Jens B Jorgensen for their advice;
however, trying out Jens idea:

>>> xpos, ypos = cd.GetPosition(0, 0)

results in this error message:

Traceback (most recent call last):
  File "<pyshell#7>", line 1, in ?
    xpos,ypos=cd.GetPosition(0,0)
  File "<COMObject CorelDraw.automation.6>", line 2, in
GetPosition
com_error: (-2147352571, 'Type mismatch.', None, 1)

Both parameters in GetPosition are 'out'. I've even tried the following,
giving the same above error message:
>>> x = 0
>>> y = 0
>>> xpos, ypos = cd.GetPosition(x, y)     # error

There are about a dozen or so of methods which return values such as
current size, line width, fill colour, etc. As a workaround, I think I'm
going to create a COM object from Excel and have
Python call a method from Excel which will call the GetPosition method
in CorelDraw and store the results on a worksheet. Python can then
retrieve the values from this sheet. Speed is not an issue here, and
besides, Draw routines implemented in Python are just as fast as those
using  Corel's version of Basic.

Thanks for the help,
George Vestergom