[python-win32] VB Interfaces
Mark Hammond
mhammond@skippinet.com.au
Thu, 12 Dec 2002 19:20:49 +1100
I agree this should work ;) However, VB does strange things.
Can you demonstrate some VBScript code against this that works correctly?
If so, then mail me and we can work through it.
Mark.
> -----Original Message-----
> From: python-win32-admin@python.org
> [mailto:python-win32-admin@python.org]On Behalf Of Blair Hall
> Sent: Thursday, 12 December 2002 2:23 PM
> To: python-win32@python.org
> Subject: [python-win32] VB Interfaces
>
>
> 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
> End Function
>
> Function getn() As Integer
> ' Return the numerical value
> End Function
>
> ' Concrete number class........ Number.cls
> Implements INumber
> Dim n As Integer
> Function INumber_setn(ByVal i As Integer)
> n = i
> End Function
>
> Function INumber_getn() As Integer
> getn = n
> End Function
>
> ' Class with a factory function ......... test.cls
> Function makeNumber(ByVal i As Integer) As INumber
> Dim n As INumber
> Set n = New Number
> n.setn i
> Set makeN = n
> Set n = Nothing
> End Function
>
> >>>>>>>>>>
>
> Now if I run makepy on this automation object, I can use these
> objects from
> Python.
> For example,
>
> >>> t = Dispatch("MyDllName.test")
> >>> n = t.makeNumber( 4 )
> >>> n.getn()
> >>> 0
>
> 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.
> e.g.:
>
> >>> i = Dispatch("MyDllName.INumber")
> >>> i.setn(3)
> >>> i.getn()
> >>> 0
>
> So I presume that when makeNumber is called
> it creates an INumber object in Python that is not being
> correctly initialised.
>
> How should I proceed, IN GENERAL, to achieve the polymorphic
> behaviour in Python that the VB code is designed to support?
>
>
> _______________________________________________
> Python-win32 mailing list
> Python-win32@python.org
> http://mail.python.org/mailman/listinfo/python-win32