visual basic -> win32com server problem

Giles Brown giles_brown at hotmail.com
Wed Feb 5 07:01:39 EST 2003


I am trying to create an application object model in Python that
I can use from a Visual Basic application via COM.

I am aiming to create a parent object that exposes a collection
property and have the collection property have a default value that 
allows indexing of an item in the collection (in the normal VB 
collection idiom).

So the VB code might look like so:

Dim App As Object
Dim Station As Object

Set App = CreateObject("MyApp.Application")
Set Station = App.Stations("MyStation")

And a short version of the Python code would be:

class Stations:

    _public_methods_ = ['Item', 'Count', 'Add', 'Remove']

    # Method definitions here

    def Item(self, *args):
        return wrapped whatever here

    # Make Item default value a la win32com.server.util.Collection
    _value_ = Item
    

class Application:

    # Registration stuff here
    _public_attrs_ = ['Stations']

    def __init__(self):
        self.Stations = win32com.server.util.wrap(Stations())

Looking at the debug trace, what happens is rather than VB invoking the
"Stations" property on the App object then invoking the default on the
Stations object, it invokes the Stations property on the App object with
"MyStation" as a argument (which is ignored by the dispatcher) so the
Stations.Item method never gets called.

My question is (sorry for the slow buildup ;-) is the behaviour of win32com
and Visual Basic correct and I just need to implement my object model
differently or is there something going on in VB or win32com that is
causing this not to work and if so what?

Thanks for any help,
Giles




More information about the Python-list mailing list