get/put Methodes on COM Objects

Mark Hammond MarkH at ActiveState.com
Fri Jul 20 05:06:40 EDT 2001


Achim Domma wrote:

> Hi,
> 
> I'm writting COM objects using win32com and want to implement Properties
> which are set/read via a get/put function. The documentation mentions the
> possibility to do that, but I can not figure out how !? Can somebody help ?

You can implement a "getter" simply by providing a method of the same 
name as the property.

Unfortunately, "put" functions do not appear supported.  This could be 
added easily - win32com\server\policy.py has a block:

       for name in ob._public_attrs_:
         self._name_to_dispid_[string.lower(name)] = dispid
         self._dispid_to_get_[dispid] = name
         if name not in readonly:
           self._dispid_to_put_[dispid] = name

This should probably handle a "set_{name}" function in the last line. 
The reason this hasn't been done yet is that I need to figure out 
exactly how to handle the DISPATCH_PROPERTYPUT and 
DISPATCH_PROPERTYPUTREF cases independently for the 1% of cases that 
care, and handle them the same for the 99% of cases that don't.

Feel free to offer up a patch that supports this, and I will integrate 
it in.  Off the top of my head, "setref_", if it exists, could be used 
to signify that you _do_ care, while "set_" would be used in the more 
general case for both.

OTOH, I guess I see no real reason to force this support now.  We have 
gone so long without even a setter - so when someone does actually care, 
we can enhance it then.

Whatever :)

Mark.




More information about the Python-list mailing list