[Tutor] COM server: cannot assign property

Alan Gauld alan.gauld at btinternet.com
Fri Nov 13 02:29:08 CET 2009


"Yashwin Kanchan" <yashwinkanchan at gmail.com> wrote

> I am trying to create a simple test COM server , but am have trouble
> assigning any property value to it through excel VBA.

I've never tried using properties via COM.
Does it work if you disable the property aspect and expose
the set/get methods directly? Can you access those methods
successfully from VB?

If that works it suggests the problem lies in the property
definition stuff...

HTH,

Alan G

> Please point out where i am going wrong.
>
>
> #COM server
> class test(object):
>
>    _reg_clsid_ = "{B5901450-F9A1-4F76-8FCF-2BFFA96ED210}"
>    _reg_progid_ = "Python.Test"
>    _public_methods_ = ["arg"]
>    _public_attrs_ = ["t"]
>
>    def __init__(self):
>        self._t=0
>
>    def arg(self,s,r):
>        return (s,r)
>
>    def get_t(self):
>        return self._t
>
>    def set_t(self,value):
>        self._t = str(value)
>
>    t = property(get_t,set_t)
>
> if __name__=='__main__':
>    import win32com.server.register
>    win32com.server.register.UseCommandLine(test)
>    print "done"
>
> VBA Code:
>
> Sub Button1_Click()
>    Set test = CreateObject("Python.Test")
>    test.arg 2, 5
>    test.t = "hello"
>    MsgBox test.t
> End Sub
>
>
> Error; "Object doesnt support this property or method" at test.t = 
> "hello"
>
> Thanks
> Yashwin Kanchan
>


--------------------------------------------------------------------------------


> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 




More information about the Tutor mailing list