Warning: Tcom has volatile handles
- From: Alexandre Ferrieux <alexandre.ferrieux@xxxxxxxxx>
- Date: Wed, 24 Sep 2008 08:19:57 -0700 (PDT)
Hi,
While playing with Tcom with both an interactive Wish and Melissa
Shrumpf's nice ComTree, I discovered one thing that might discourage
newcomers (to COM and/or Tcom) like me: the handles returned by
[::tcom::ref createobject] are *volatile*, i.e. they disappear as soon
as Tcl holds no more reference to the initial (Tcl) object created to
wrap them.
The net effect is that you type in wish:
% package require tcom
3.9
% ::tcom::ref createobject SomeApi.SomeClass
::tcom::handle0x00939CB0
But if then you copy and paste the above returned handle in:
% ::tcom::info interface ::tcom::handle0x00939CB0
you get an error saying the interface cannot be obtained.
The workaround, of course, is to avoid the string-only path of copy/
paste and use a variable keeping a reference alive:
% set h [::tcom::ref createobject SomeApi.SomeClass]
% ::tcom::info interface $h
This quirk places Tcom in the confidential circle of "Feather-like"
extensions, meaning they violate the EIAS principle. Getting out of
this circle involves explicitly managing the lifecycle of such opaque
objects, like file handles in Tcl. But I can understand that in the
COM world it is better the way it is, because APIs tend to generate
many sub-objects from a root one (e.g. interfaces), and tying their
lifecycle to that of internal reps of Tcl values is a quick solution
for the script programmer. Maybe a warning in the docs is all there's
to do...
-Alex
.
- Follow-Ups:
- Re: Warning: Tcom has volatile handles
- From: Alexandre Ferrieux
- Re: Warning: Tcom has volatile handles
- Prev by Date: Re: Switching from Tk to Ttk
- Next by Date: Re: Switching from Tk to Ttk
- Previous by thread: [ANNOUNCE] Aejaks 1.1
- Next by thread: Re: Warning: Tcom has volatile handles
- Index(es):
Relevant Pages
|