Overview
| Artifact ID: | f41113ff11404cd48f1b445996764d92f938f6ae |
|---|---|
| Ticket: | 2969488fffffffffffffffffffffffffffffffff
trace variable doesn't fire if you upvar to an array element |
| User & Date: | twylite on 2010-03-12 16:04:58 |
Changes
- assignee changed to: "msofer"
- cmimetype changed to: "text/plain"
- comment changed to:
(This is FR 572889 from June 2002 converted to a bug) Tcl Versions: all 8.4 and onwards; confirmed on 8.4.11 and 8.6b1.1 OS platform and version: probably all, confirmed on Windows XP + SP3 Problem behaviour: If you set a trace on an array, then link to a specific element of that array using [upvar], any changes made via the linked variable will not cause traces to fire. Expected behaviour: If a trace has been placed on a variable, any access to that variable (even indirectly) should invoke the trace. Additional detail / Use case I have a "fileentry" megawidget that combines an entry, a button with an icon, and a tk_getOpenFile / tk_getSaveFile. If the button is clicked the appropriate file dialog is displayed, and the selected filename written back into the -textvariable. The obvious implementation is to link to the -textvariable using [upvar]. If the -textvariable is an array element then traces on the element will not fire. In this case I am using variable traces to maintain consistency between various UI fields, so I lose consistency if the trace doesn't fire. Workarounds (1) Change the UI to use a scalar rather than an array element for this field (2) set and dereference the varname given by -textvariable directly rather than using [upvar] (3) have the megawidget use the entry's get/insert/delete methods rather than accessing -textvariable. Code sample --- proc tracer {args} { puts "<trace> $args" } set ui(field1) "alpha" trace add variable ui write "tracer write" trace add variable ui array "tracer array" set ui(field1) "beta" ;# trace write fires array set ui {field1 "gamma"} ;# trace write & array both fire proc alter {varname} { upvar #0 $varname v set v "delta" } alter ui(field1) ;# trace doesn't fire --- - foundin changed to: "obsolete: 8.6b1.1"
- is_private changed to: "0"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- status changed to: "Open"
- submitter changed to: "twylite"
- subsystem changed to: "07. Variables"
- title changed to:
trace variable doesn't fire if you upvar to an array element
- type changed to: "Bug"