1scope(n)                          [incr Tcl]                          scope(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       itcl::scope - capture the namespace context for a variable
9

SYNOPSIS

11       itcl::scope name
12______________________________________________________________________________
13
14

DESCRIPTION

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  name which will resolve in any context as an instance vari‐
19       able belonging to object.  The precise format of this name is an inter‐
20       nal  detail  to  Itcl.  Use of such a scoped value makes it possible to
21       use instance variables in conjunction with widgets.   For  example,  if
22       you have an object with a private variable x, and you can use x in con‐
23       junction with the -textvariable option  of  an  entry  widget.   Before
24       itcl3.0, only common variables could be used in this manner.
25
26       If the name is not an instance variable, then it must be a common vari‐
27       able or a global variable.  In that case, the scope command returns the
28       fully qualified name of the variable, e.g., ::foo::bar::x.
29
30       If  the name is not recognized as a variable, the scope command returns
31       an error.
32
33       Ordinary variable names refer to variables in the global namespace.   A
34       scoped  value captures a variable name together with its namespace con‐
35       text in a way that allows it to be referenced properly  later.   It  is
36       needed, for example, to wrap up variable names when a Tk widget is used
37       within a namespace:
38              namespace foo {
39                  private variable mode 1
40
41                  radiobutton .rb1 -text "Mode #1"         -variable [scope mode] -value 1
42                  pack .rb1
43
44                  radiobutton .rb2 -text "Mode #2"         -variable [scope mode] -value 2
45                  pack .rb2
46              }
47       Radiobuttons .rb1 and .rb2 interact via the variable  "mode"  contained
48       in the namespace "foo".  The scope command guarantees this by returning
49       the fully qualified variable name ::foo::mode.
50
51       You should never attempt to craft your own scoped variable names,  even
52       if  you  believe  you've  flawlessly  reverse-engineered  the encoding.
53       Instead, you should always use the scope command to generate the  vari‐
54       able  name dynamically.  Then, you can pass that name to a widget or to
55       any other bit of code in your program.
56
57

KEYWORDS

59       code, namespace, variable
60
61
62
63itcl                                                                  scope(n)
Impressum