2013-06-05 50 views
0

我是很新的ITCL可以有一个人帮助我如何转换的Tcl follwing代码ITCL皈依到ITCL

catch { namespace delete ::HVToolSet } 
namespace eval ::HVToolSet { } { 
} 
proc ::HVToolSet::Main {} { 
    if {[winfo exists .main]} { 
     destroy .main 
    } 
    set ::HVToolSet::base [toplevel .main] 
    variable tab_frame 
    set x 200 
    set y 200 
    wm geometry $::HVToolSet::base ${x}x${y}+100+0 
    wm title $::HVToolSet::base "Chevron's Build Effective Stress Results Tool" 
    wm focusmodel $::HVToolSet::base passive  
    set creatFrame [frame .main.mnFrame] 
    pack $creatFrame -side top -anchor nw -expand 1 -fill both -padx 7 -pady 7 

    button $creatFrame.okbutton -text "OK" -command ::HVToolSet::okcall 
    pack $creatFrame.okbutton -side top 
} 

proc ::HVToolSet::okcall {} { 
    ::HVToolSet::checkRun "right" 
} 

proc ::HVToolSet::checkRun {val} { 
    set abc 10 
    ::newspace::exec $abc # another name space method calling 
} 

::HVToolSet::Main 
+0

我一直认为[incr Tcl]是Tcl的扩展。我建议在开始时添加一个'包需要Itcl'。 –

+0

如果程序来自其他命名空间,那么程序和我们如何表示过程调用的情况如何? – surendra

回答

1

首先,映射并不确切。你正从一个没有阶级的系统转变为一个系统,这是一个根本性的细微差别。

然而,粗略地说,一个过程变成了一种方法,一个名字空间变成了一个类。这至少在做什么第一近似:

package require Itcl 

itcl::class HVToolSet { 
    # Shared over all instances (and unused otherwise?!) 
    common variable tab_frame "" 
    # Specific to each instance of this class 
    private variable base "" 

    # 'Main' seemed to be a constructor of some sort 
    constructor {{win .main}} { 
     if {[winfo exists $win]} { 
      destroy $win 
     } 
     set base [toplevel $win] 
     set x 200 
     set y 200 
     wm geometry $base ${x}x${y}+100+0 
     wm title $base "Chevron's Build Effective Stress Results Tool" 
     wm focusmodel $base passive  
     set creatFrame [frame $base.mnFrame] 
     pack $creatFrame -side top -anchor nw -expand 1 -fill both -padx 7 -pady 7 

     button $creatFrame.okbutton -text "OK" -command [itcl::code okcall] 
     pack $creatFrame.okbutton -side top 
    } 

    # Obvious destructor... 
    destructor { 
     destroy $base 
    } 

    # Callback, best done as private method 
    private method okcall {} { 
     $this checkRun "right" 
    } 

    # Public method... 
    method checkRun {val} { 
     set abc 10 
     ::newspace::exec $abc ; # another name space method calling 
    } 
} 

# Make an instance of the class that operates with the window .main 
HVToolSet myInstance .main 

工作什么需要一个构造函数,什么是私有方法,什么公共方法可以采取一些心思。一般来说,构造函数创建和初始化事物,私有方法只在类中有意义(例如,处理回调或重构复杂东西),公共方法在外部调用时可能意味着什么。