From: Donal K. Fellows on
On 24 Jan, 11:58, Georgios Petasis <peta...(a)iit.demokritos.gr> wrote:
> And the most difficult part: can I link three variables from three
> objects? There is a public variable named "language" that must have the
> same value in all three objects (from A, B & C). Is there a way to do
> this? (Traces?)

Assuming you've got a recent enough version of TclOO (I do not
recommend using anything before 0.6.2) you can use [info object
namespace] to get the location of the instance variables used by a
particular object. Combine that with [namespace upvar] and [my eval]
and you can make the variable in one object be identical to the
variable in another (just like with [global] or [upvar]).

Donal.
From: George Petasis on
στις 24/1/2010 18:51, O/H Donal K. Fellows έγραψε:
> On 24 Jan, 11:58, Georgios Petasis<peta...(a)iit.demokritos.gr> wrote:
>> And the most difficult part: can I link three variables from three
>> objects? There is a public variable named "language" that must have the
>> same value in all three objects (from A, B& C). Is there a way to do
>> this? (Traces?)
>
> Assuming you've got a recent enough version of TclOO (I do not
> recommend using anything before 0.6.2) you can use [info object
> namespace] to get the location of the instance variables used by a
> particular object. Combine that with [namespace upvar] and [my eval]
> and you can make the variable in one object be identical to the
> variable in another (just like with [global] or [upvar]).
>
> Donal.

I have used code similar to:

oo::objdefine $obj export varname
foreach var {language annotation attribute alternative groups values} {
upvar [$obj varname $var] [my varname $var]
}

It seems to work. I am using 0.6.1 (latest ActiveTcl beta).
The only problem I had was varname not returning array elements, which I
solved with "[my varname array_name](element)".

Thanks,

George