home *** CD-ROM | disk | FTP | other *** search
/ Practical Programming in Tcl & Tk (4th Edition) / TCLBOOK4.BIN / pc / exsource.old / 13_8.tcl < prev    next >
Text File  |  2003-04-15  |  472b  |  28 lines

  1. #
  2. # Example 13-8
  3. # Tracing variables.
  4. #
  5.  
  6. proc ReadOnlyVar {varName} {
  7.     upvar 1 $varName var
  8.     global ReadOnly
  9.     set ReadOnly($varName) $var
  10.     uplevel 1 [list trace variable $varName wu ReadOnlyTrace]
  11. }
  12. proc ReadOnlyTrace { varName index op } {
  13.     global ReadOnly
  14.     upvar 1 $varName var
  15.     switch $op {
  16.         w {
  17.             set var $ReadOnly($varName)
  18.         }
  19.         u {
  20.             set var $ReadOnly($varName)
  21.             # Re-establish the trace using the true name
  22.             uplevel 1 [list ReadOnlyVar $varName]
  23.         }
  24.     }
  25. }
  26.  
  27.  
  28.