Sujet : Re: A TclOO question
De : rich (at) *nospam* example.invalid (Rich)
Groupes : comp.lang.tclDate : 18. May 2025, 02:31:06
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <100bd8q$lh31$1@dont-email.me>
References : 1
User-Agent : tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Helmut Giese <
hgiese@ratiosoft.com> wrote:
Hello out there,
say I have a class and 2 instances like so
oo::class create MyClass {
constructor {someVal} {
my variable myVar
set myVar $someVal
}
method get {} {
my variable myVar
return $myVar
}
method set {val} {
my variable myVar
set myVar $val
}
}
MyClass create obj1 33
MyClass create obj2 99
How can I set a trace on 'myVar' of 'obj2'?
I found an example on the doc of the 'my' command but it sets a trace
on a global variable during which an object is invoked - which doesn't
fit my situation
Any help will be greatly appreciated
Helmut
From outside the object, one way is, after you create the objects:
Get the object's namespace:
% info object namespace obj2
::oo::Obj13
Then infer the location of the variable:
% set ::oo::Obj13::myVar
99
Setting a trace on ::oo::Obj13::myVar should be trivial now.
From inside one of the object's methods, the 'my varname' gives you the
full namespace name:
oo::class create MyClass {
constructor {someVal} {
my variable myVar
set myVar $someVal
}
method where {} {
puts "myVar is at [my varname myVar]"
}
}
::MyClass
% MyClass create obj1 33
::obj1
% obj1 where
myVar is at ::oo::Obj12::myVar
%