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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [itcl/] [itcl/] [doc/] [scope.n] - Diff between revs 578 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 578 Rev 1765
'\"
'\"
'\" Copyright (c) 1993-1998  Lucent Technologies, Inc.
'\" Copyright (c) 1993-1998  Lucent Technologies, Inc.
'\"
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
'\"
'\" RCS: $Id: scope.n,v 1.1.1.1 2002-01-16 10:24:46 markom Exp $
'\" RCS: $Id: scope.n,v 1.1.1.1 2002-01-16 10:24:46 markom Exp $
'\"
'\"
.so man.macros
.so man.macros
.TH scope n "" Tcl "[incr\ Tcl]"
.TH scope n "" Tcl "[incr\ Tcl]"
.BS
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
.SH NAME
scope \- capture the namespace context for a variable
scope \- capture the namespace context for a variable
.SH SYNOPSIS
.SH SYNOPSIS
\fBscope \fIname\fR
\fBscope \fIname\fR
.BE
.BE
.SH DESCRIPTION
.SH DESCRIPTION
.PP
.PP
Creates a scoped value for the specified \fIname\fR, which must
Creates a scoped value for the specified \fIname\fR, which must
be a variable name.  If the \fIname\fR is an instance variable,
be a variable name.  If the \fIname\fR is an instance variable,
then the scope command returns a string of the following form:
then the scope command returns a string of the following form:
.CS
.CS
@itcl \fIobject varName\fP
@itcl \fIobject varName\fP
.CE
.CE
This is recognized in any context as an instance variable belonging
This is recognized in any context as an instance variable belonging
to \fIobject\fR.  So with itcl3.0 and beyond, it is possible to use
to \fIobject\fR.  So with itcl3.0 and beyond, it is possible to use
instance variables in conjunction with widgets.  For example, if you
instance variables in conjunction with widgets.  For example, if you
have an object with a private variable \fCx\fR, and you can use
have an object with a private variable \fCx\fR, and you can use
\fCx\fR in conjunction with the \fC-textvariable\fR option of an
\fCx\fR in conjunction with the \fC-textvariable\fR option of an
entry widget.  Before itcl3.0, only common variables could be used
entry widget.  Before itcl3.0, only common variables could be used
in this manner.
in this manner.
.PP
.PP
If the \fIname\fR is not an instance variable, then it must be
If the \fIname\fR is not an instance variable, then it must be
a common variable or a global variable.  In that case, the scope
a common variable or a global variable.  In that case, the scope
command returns the fully qualified name of the variable, e.g.,
command returns the fully qualified name of the variable, e.g.,
\fC::foo::bar::x\fR.
\fC::foo::bar::x\fR.
.PP
.PP
If the \fIname\fR is not recognized as a variable, the scope
If the \fIname\fR is not recognized as a variable, the scope
command returns an error.
command returns an error.
.PP
.PP
Ordinary variable names refer to variables in the global namespace.
Ordinary variable names refer to variables in the global namespace.
A scoped value captures a variable name together with its namespace
A scoped value captures a variable name together with its namespace
context in a way that allows it to be referenced properly later.
context in a way that allows it to be referenced properly later.
It is needed, for example, to wrap up variable names when a Tk
It is needed, for example, to wrap up variable names when a Tk
widget is used within a namespace:
widget is used within a namespace:
.CS
.CS
namespace foo {
namespace foo {
    private variable mode 1
    private variable mode 1
    radiobutton .rb1 -text "Mode #1" \
    radiobutton .rb1 -text "Mode #1" \
        -variable [scope mode] -value 1
        -variable [scope mode] -value 1
    pack .rb1
    pack .rb1
    radiobutton .rb2 -text "Mode #2" \
    radiobutton .rb2 -text "Mode #2" \
        -variable [scope mode] -value 2
        -variable [scope mode] -value 2
    pack .rb2
    pack .rb2
}
}
.CE
.CE
Radiobuttons \fC.rb1\fR and \fC.rb2\fR interact via the variable
Radiobuttons \fC.rb1\fR and \fC.rb2\fR interact via the variable
"mode" contained in the namespace "foo".  The \fBscope\fR command
"mode" contained in the namespace "foo".  The \fBscope\fR command
guarantees this by returning the fully qualified variable name
guarantees this by returning the fully qualified variable name
\fC::foo::mode\fR.
\fC::foo::mode\fR.
.PP
.PP
You should never use the \fC@itcl\fR syntax directly.  For example,
You should never use the \fC@itcl\fR syntax directly.  For example,
it is a bad idea to write code like this:
it is a bad idea to write code like this:
.CS
.CS
set {@itcl ::fred x} 3
set {@itcl ::fred x} 3
puts "value = ${@itcl ::fred x}"
puts "value = ${@itcl ::fred x}"
.CE
.CE
Instead, you should always use the scope command to generate the
Instead, you should always use the scope command to generate the
variable name dynamically.  Then, you can pass that name to a widget
variable name dynamically.  Then, you can pass that name to a widget
or to any other bit of code in your program.
or to any other bit of code in your program.
.SH KEYWORDS
.SH KEYWORDS
code, namespace, variable
code, namespace, variable
 
 

powered by: WebSVN 2.1.0

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