Python and COM: a bug?
htrd90 at zepler.org
Sun Nov 28 23:44:08 CET 1999
Gaetan Corneau <Gaetan_Corneau at baan.com> wrote:
>fromwin32com.client.dynamic import Dispatch
>am = Dispatch("ITK.AdapterManager")
>ad = am.GetAdapter("OLEDB")
>Conn = ad.NewConnection()
>Conn.Open("/dsn:HPD380 /user:gc /pwd:qwerty")
>for Employee in Conn.Classes("Employee").GetObjects():
> print Employee.Name
>What do we use all that for? In an integration server that manipulates
>abstract data, reading from a source, writing to a destination. The server
>lets you define data magppings graphically (for simple one to one field
>mapping). All that stuff has nothing to do with COM. The objects containing
>the data are C++ object. But when the mapping is complex, we create a COM
>wrapper over those C++ object (ITKDataObject) and send them to a script
>using ActiveX Scripting.
>So, the problem is this. When I access "Employee.Name", I get the ID for the
>Name property of Employee, but the Python COM caches it for ITKDataObject
Not quite. Clients are only allowed to cache the ID for use with that
one object. DISPIDs are allowed to be different between instances of
one class, just not during the lifetime of one object.
>From what you have described (if I understand correctly) then you
should be ok????????
>> ob = pythoncom.CoCreateInstance("Your.ProgID", None, pythoncom.CLSCTX_ALL,
>> dispid = ob.GetIDsOfNames("foo")
>> print dispid
>> dispid2 = ob.GetIDsOfNames("foo")
>> print dispid2
>> if dispid != dispid2:
>> print "Eeek"
ob2 = pythoncom.CoCreateInstance(...as above..)
dispid3 = ob2.GetIDsOfNames("foo")
if dispid != dispid3:
print "Not so strange"
>> If it is the problem, you are clearly breaking the rules, and there is
>> a good chance that later versions of VBScript, or indeed any other COM
>> compatible language would also break.
>Now, this is a potentially severe bug. For the time being, the integration
>server is "locked" so all scripts must be written in VBScript, but it may
>not be so in future version. Another thing that could go wrong is that there
>is a new version of VBScript available. I haven't tried it yet, but I will:
>maybe this version uses caching.
iirc, the dispinterface proxy caches DISPIDs too. You might see the
problem even with VBScript if there is marshalling involved :-(
htrd90 at zepler.org
More information about the Python-list