1scope(n) [incr Tcl] scope(n)
2
3
4
5______________________________________________________________________________
6
8 itcl::scope - capture the namespace context for a variable
9
11 itcl::scope name
12______________________________________________________________________________
13
14
16 Creates a scoped value for the specified name, which must be a variable
17 name. If the name is an instance variable, then the scope command
18 returns a string of the following form:
19 @itcl object varName
20 This is recognized in any context as an instance variable belonging to
21 object. So with itcl3.0 and beyond, it is possible to use instance
22 variables in conjunction with widgets. For example, if you have an
23 object with a private variable x, and you can use x in conjunction with
24 the -textvariable option of an entry widget. Before itcl3.0, only com‐
25 mon variables could be used in this manner.
26
27 If the name is not an instance variable, then it must be a common vari‐
28 able or a global variable. In that case, the scope command returns the
29 fully qualified name of the variable, e.g., ::foo::bar::x.
30
31 If the name is not recognized as a variable, the scope command returns
32 an error.
33
34 Ordinary variable names refer to variables in the global namespace. A
35 scoped value captures a variable name together with its namespace con‐
36 text in a way that allows it to be referenced properly later. It is
37 needed, for example, to wrap up variable names when a Tk widget is used
38 within a namespace:
39 namespace foo {
40 private variable mode 1
41
42 radiobutton .rb1 -text "Mode #1" -variable [scope mode] -value 1
43 pack .rb1
44
45 radiobutton .rb2 -text "Mode #2" -variable [scope mode] -value 2
46 pack .rb2
47 }
48 Radiobuttons .rb1 and .rb2 interact via the variable "mode" contained
49 in the namespace "foo". The scope command guarantees this by returning
50 the fully qualified variable name ::foo::mode.
51
52 You should never use the @itcl syntax directly. For example, it is a
53 bad idea to write code like this:
54 set {@itcl ::fred x} 3
55 puts "value = ${@itcl ::fred x}"
56 Instead, you should always use the scope command to generate the vari‐
57 able name dynamically. Then, you can pass that name to a widget or to
58 any other bit of code in your program.
59
60
62 code, namespace, variable
63
64
65
66itcl scope(n)