OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [itcl/] [itcl/] [doc/] [scope.n] - Blame information for rev 1771

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
'\"
2
'\" Copyright (c) 1993-1998  Lucent Technologies, Inc.
3
'\"
4
'\" See the file "license.terms" for information on usage and redistribution
5
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6
'\"
7
'\" RCS: $Id: scope.n,v 1.1.1.1 2002-01-16 10:24:46 markom Exp $
8
'\"
9
.so man.macros
10
.TH scope n "" Tcl "[incr\ Tcl]"
11
.BS
12
'\" Note:  do not modify the .SH NAME line immediately below!
13
.SH NAME
14
scope \- capture the namespace context for a variable
15
.SH SYNOPSIS
16
\fBscope \fIname\fR
17
.BE
18
 
19
.SH DESCRIPTION
20
.PP
21
Creates a scoped value for the specified \fIname\fR, which must
22
be a variable name.  If the \fIname\fR is an instance variable,
23
then the scope command returns a string of the following form:
24
.CS
25
@itcl \fIobject varName\fP
26
.CE
27
This is recognized in any context as an instance variable belonging
28
to \fIobject\fR.  So with itcl3.0 and beyond, it is possible to use
29
instance variables in conjunction with widgets.  For example, if you
30
have an object with a private variable \fCx\fR, and you can use
31
\fCx\fR in conjunction with the \fC-textvariable\fR option of an
32
entry widget.  Before itcl3.0, only common variables could be used
33
in this manner.
34
.PP
35
If the \fIname\fR is not an instance variable, then it must be
36
a common variable or a global variable.  In that case, the scope
37
command returns the fully qualified name of the variable, e.g.,
38
\fC::foo::bar::x\fR.
39
.PP
40
If the \fIname\fR is not recognized as a variable, the scope
41
command returns an error.
42
.PP
43
Ordinary variable names refer to variables in the global namespace.
44
A scoped value captures a variable name together with its namespace
45
context in a way that allows it to be referenced properly later.
46
It is needed, for example, to wrap up variable names when a Tk
47
widget is used within a namespace:
48
.CS
49
namespace foo {
50
    private variable mode 1
51
 
52
    radiobutton .rb1 -text "Mode #1" \
53
        -variable [scope mode] -value 1
54
    pack .rb1
55
 
56
    radiobutton .rb2 -text "Mode #2" \
57
        -variable [scope mode] -value 2
58
    pack .rb2
59
}
60
.CE
61
Radiobuttons \fC.rb1\fR and \fC.rb2\fR interact via the variable
62
"mode" contained in the namespace "foo".  The \fBscope\fR command
63
guarantees this by returning the fully qualified variable name
64
\fC::foo::mode\fR.
65
.PP
66
You should never use the \fC@itcl\fR syntax directly.  For example,
67
it is a bad idea to write code like this:
68
.CS
69
set {@itcl ::fred x} 3
70
puts "value = ${@itcl ::fred x}"
71
.CE
72
Instead, you should always use the scope command to generate the
73
variable name dynamically.  Then, you can pass that name to a widget
74
or to any other bit of code in your program.
75
 
76
.SH KEYWORDS
77
code, namespace, variable

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.