[python-win32] VB Interfaces
Thu, 12 Dec 2002 16:23:20 +1300
This is really my first foray into the world of Python and COM
so I may be asking a dumb question. Here goes.
I have been trying to write client code for a
collection of small automation objects written in VB (by me).
The VB code uses an interface to support polymorphic behaviour
from a number of different classes. Unfortunately, Python
is not handling this interface the way I expected it to.
The following is not the actual code, but it shows
where my thinking about this comes unstuck:
>>>>>>>>>> VB classes (complied into a dll):
' Interface class ...... INumber .cls
Function setn(ByVal i As Integer)
' Set the numerical value
Function getn() As Integer
' Return the numerical value
' Concrete number class........ Number.cls
Dim n As Integer
Function INumber_setn(ByVal i As Integer)
n = i
Function INumber_getn() As Integer
getn = n
' Class with a factory function ......... test.cls
Function makeNumber(ByVal i As Integer) As INumber
Dim n As INumber
Set n = New Number
Set makeN = n
Set n = Nothing
Now if I run makepy on this automation object, I can use these objects from
>>> t = Dispatch("MyDllName.test")
>>> n = t.makeNumber( 4 )
which is not the answer expected!
If I re-write makeNumber to use only Number objects
the Python code above works.
Now, I may be wrong, but it seems that an
INumber object can be created without
being a reference to a Number object.
>>> i = Dispatch("MyDllName.INumber")
So I presume that when makeNumber is called
it creates an INumber object in Python that is not being
How should I proceed, IN GENERAL, to achieve the polymorphic
behaviour in Python that the VB code is designed to support?