Python COM Server

Bjorn Pettersen bjorn at roguewave.com
Fri May 19 18:51:31 EDT 2000


I believe your problem is that VB is calling SplitString with the
default argument (i.e. None), and then you are passing it (None) to
string.split, ie. your call is string.split(str(val), None).

I would probably code it like:

def SplitString(self, val, item=None):
  import string
  if item is None:
     item = ''
  else:
     item = str(item)
  return string.split(str(val), item)

-- bjorn

Chris wrote:
> 
> I am trying to build a COM object with Python that I can reference from VB.
> I have followed examples in Python-programming on Win32 and from other
> sources.  I manage to register the COM objects and in VB it does the
> "CreateObject" bit but will not allow me to call a method of one of my COM
> objects.
> 
> I am a final year degree student trying to build a simple COM/CORBA bridge
> demonstration using Python, so if anyone can help I would really appreciate
> it.
> 
> This is my Python code;
> 
> #PythonSplitutil
> #Chris Rowley
> #12 May 2000
> class PythonSplit:
>  _public_methods_ = ['SplitString']
>  _reg_progid_ = "PythonDemos.Split"
>  _reg_clsid_ = "{2222EEB8-790E-4B9D-B8F6-41E05A4A0F2D}"
> 
> def SplitString(self, val, item=None):
>  import string
>  if item != None: item = str(item)
>  return string.split(str(val), item)
> 
> if __name__=='__main__':
>  print "Registering COM Server..."
>  import win32com.server.register
>  win32com.server.register.UseCommandLine(PythonSplit)
> 
> And this is the VB code which fails;
> 
> Private Sub Command1_Click()
> Dim pu As Object
>  Set pu = CreateObject("PythonDemos.Split")
>  Dim r As Variant
>  r = pu.SplitString("hello from VB")    '**
>   MsgBox r
> End Sub
> 
> It fails on the line marked ** with error message "Run-time error '438'
> Object doesn't support this property or method"
> 
> I presume from this that the object is registered but the method isn't?  Is
> there a make type library function that I am missing?
> 
> Chris Rowley
> 
> --
> Chris Rowley
> 
> --
> http://www.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list