OSDN Git Service

Please enter the commit message for your changes. Lines starting
[eos/base.git] / util / src / TclTk / tcl8.6.12 / pkgs / itcl4.2.2 / doc / local.n
1 '\"
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 .TH local n "" itcl "[incr\ Tcl]"
8 .so man.macros
9 .BS
10 '\" Note:  do not modify the .SH NAME line immediately below!
11 .SH NAME
12 itcl::local \- create an object local to a procedure
13 .SH SYNOPSIS
14 \fBitcl::local \fIclassName objName\fR ?\fIarg arg ...\fR?
15 .BE
16
17 .SH DESCRIPTION
18 .PP
19 The \fBlocal\fR command creates an \fB[incr\ Tcl]\fR object that
20 is local to the current call frame.  When the call frame goes away,
21 the object is automatically deleted.  This command is useful for
22 creating objects that are local to a procedure.
23 .PP
24 As a side effect, this command creates a variable named
25 "\fBitcl-local-\fIxxx\fR", where \fIxxx\fR is the name of
26 the object that is created.  This variable detects when the
27 call frame is destroyed and automatically deletes the
28 associated object.
29
30 .SH EXAMPLE
31 .PP
32 In the following example, a simple "counter" object is used
33 within the procedure "test".  The counter is created as a
34 local object, so it is automatically deleted each time the
35 procedure exits.  The \fBputs\fR statements included in the
36 constructor/destructor show the object coming and going
37 as the procedure is called.
38 .PP
39 .CS
40 itcl::class counter {
41     private variable count 0
42     constructor {} {
43         puts "created: $this"
44     }
45     destructor {
46         puts "deleted: $this"
47     }
48
49     method bump {{by 1}} {
50         incr count $by
51     }
52     method get {} {
53         return $count
54     }
55 }
56
57 proc test {val} {
58     local counter x
59     for {set i 0} {$i < $val} {incr i} {
60         x bump
61     }
62     return [x get]
63 }
64
65 set result [test 5]
66 puts "test: $result"
67
68 set result [test 10]
69 puts "test: $result"
70
71 puts "objects: [itcl::find objects *]"
72 .CE
73
74 .SH KEYWORDS
75 class, object, procedure