【问题标题】:Using trace to execute a proc in TCL在 TCL 中使用 trace 执行 proc
【发布时间】:2013-05-08 10:26:29
【问题描述】:

我在 TCL/Tk 应用程序中有以下内容:

 proc greyout { } {
     puts "current part $DSM::Part"
     switch $DSM::Part {
 Doghouse {
     for {set entry 1} {$entry<17} {incr entry} { 
         .dsm.traceCTRpart$entry  configure -state disabled
         .dsm.traceLATpart$entry  configure -state disabled
         .dsm.traceStowage$entry  configure -state disabled      
         .dsm.traceDoghouse$entry configure -state enabled}
        }
  Stowage {
     for {set entry 1} {$entry<17} {incr entry} { 
         .dsm.traceCTRpart$entry configure -state disabled
         .dsm.traceLATpart$entry configure -state disabled
         .dsm.traceStowage$entry configure -state enabled        
         .dsm.traceDoghouse$entry configure -state disabled}
        }   
     }   
 }

  trace add variable DSM::Part write greyout

每次“部分”更改跟踪尝试调用灰色但我收到以下消息:

 wrong # args: should be "greyout"
 wrong # args: should be "greyout"
 while executing
"greyout Part {} write"
(write trace on "Part")
invoked from within
"variable Part "CTR_Partition""
(in namespace eval "::DSM" script line 3)
invoked from within.....

我不明白为什么?!有什么帮助吗?

【问题讨论】:

    标签: tcl trace


    【解决方案1】:

    问题在于,当触发跟踪回调时,会在回调中附加额外的参数,这些参数用于提供有关触发回调的触发事件的信息。由于您的代码仅对单个变量进行跟踪,因此这些参数目前对您不是很有用,但它们在更复杂的情况下会很有帮助。

    调整代码以处理此问题的最简单方法是使用特殊的args 形式参数使greyout 采用任意数量的参数:

    proc greyout {args} {
        puts "current part $DSM::Part"
        ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多