Mark,

Our axscript host implementation is based around the old "ActiveScriptHost"
class by Ernest Laurentin. Our base collection class is a template class
implements _NewEnum, Count and other functions as per this dispatch map:

DISP_PROPERTY_EX_ID(C##BaseName, "_NewEnum", DISPID_NEWENUM, _NewEnum,
SetNotSupported, VT_UNKNOWN)
DISP_PROPERTY_EX_ID(C##BaseName, "Count", DISP_ID_COUNT, GetCount,
SetNotSupported, VT_I2)
DISP_FUNCTION(C##BaseName, "Add", Add, VT_DISPATCH, VTS_VARIANT VTS_VARIANT)
DISP_FUNCTION(C##BaseName, "Item", GetItem, VT_DISPATCH, VTS_VARIANT)
DISP_FUNCTION(C##BaseName, "Remove", Remove, VT_EMPTY, VTS_VARIANT)
DISP_DEFVALUE(C##BaseName, "Item")

I'm not sure where this came from now, probably from one of the MS MFC
samples, possibly XRTFrame. The implementation of Next does "return
ResultFromScode(S_FALSE)" on reaching the end of the list of available
items.

The debug tracing inside our app shows that all the expected objects are
being created and destroyed, so it may be something wrong in our internal
'wiring' that relates the scriptable objects to our internal data model
objects that is not properly tidying up.

We have yet to prove that it really is the absence of a StopIteration
exception that is causing the app crash, so we are continuing to unpick the
code.

Best regards,
David. 

-----Original Message-----
From: Mark Hammond [mailto:skippy.hamm...@gmail.com] 
Sent: 17 April 2012 02:15
To: supp...@pulsonix.com
Cc: python-win32@python.org
Subject: Re: [python-win32] Need advice on iterator implementation in
scripting host

On 13/04/2012 9:14 PM, Pulsonix Tech Support wrote:
> We have an ActiveX scripting host implementation in our application 
> (written in C++), so that users can run scripts to access our data 
> from inside the application.
>
> Current problem is that iterating from Python script doesn't work right.
> You can iterate through a collection, but attempts to do this a second 
> time cause application crashes or unexpected behaviour. Seems to work 
> okay from VBscript though.
>
> This may be because we are not raising StopIteration exception when
> iterator.Next() has no items left. But I can't find any information 
> about how to do this from a C++ scripting host implementation.

win32com has some iterator support built in, but was done way before Python
itself had proper iterators so probably isn't ideal.  The most basic support
is enabled when the object has a "Count" property and an
Item() method.  Some support for IEnumVARIANT also exists, but it requires
you to wrap the object in win32com.client.util.Iterator - which I should
possibly revisit as we might be able to make that seamless.

How are you attempting to expose iteration?

Mark


_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to