home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / tcl / 1866 < prev    next >
Encoding:
Internet Message Format  |  1992-11-17  |  1.9 KB

  1. Path: sparky!uunet!ogicse!uwm.edu!zaphod.mps.ohio-state.edu!menudo.uh.edu!sugar!karl
  2. From: karl@NeoSoft.com (Karl Lehenbauer)
  3. Newsgroups: comp.lang.tcl
  4. Subject: Re: variable visibility problem
  5. Message-ID: <BxwI80.MFB@NeoSoft.com>
  6. Date: 18 Nov 92 07:31:04 GMT
  7. Article-I.D.: NeoSoft.BxwI80.MFB
  8. References: <PRZEMEK.92Nov17130700@rrdstrad.nist.gov>
  9. Organization: NeoSoft Communications Services -- (713) 684-5900
  10. Lines: 37
  11.  
  12. In article <PRZEMEK.92Nov17130700@rrdstrad.nist.gov> przemek@rrdstrad.nist.gov (Przemek Klosowski) writes:
  13. >      [button $w.plot.Qp -text "E-Q-space plot" -relief raised \
  14. >                        -command "MyPlot $num $w $zoomfac"] {right}
  15. >Of course the code above does not work, because $zoomfac is evaluated
  16. >once at the creation of button, and the MyPlot command is called with
  17. >a constant argument. My second try was
  18. >      [button $w.plot.Qp -text "E-Q-space plot" -relief raised \
  19. >                        -command {MyPlot $num $w $zoomfac}] {right}
  20. >but this in turn fails, because $num is not a valid variable in the
  21. >routine from which MyPlot is called.
  22.  
  23.       [button $w.plot.Qp -text "E-Q-space plot" -relief raised \
  24.                         -command "MyPlot $num $w \$zoomfac"] {right}
  25.                          ^
  26. You can use backslash to quote a dollar sign ----^ and get it evaluated
  27. when the button is pressed rather than when the button is created.
  28.  
  29. I have seen a tendency on the part of myself and others to write some 
  30. fairly huge -command arguments with a lot of exotic quoting to get 
  31. things to come out just right.  I would rather that we subsume this
  32. complexity into procs to make it easier to read and understand, something
  33. like:
  34.  
  35. proc plot_button {num w} {
  36.     global zoomfac
  37.  
  38.     MyPlot $num $w $zoomfac
  39. }
  40.  
  41.     button $w.plot.Qp -text "E-Q-space plot" -relief raised \
  42.         -command "plot_button $num $w"
  43.  
  44.     pack $w.plot.Qp ...
  45.  
  46. -- 
  47. -- Email info@NeoSoft.com for info on getting interactive Internet access.
  48. "Turn on your hot tub by email now.  Ask me how."
  49.