## Tcl9.0.3/Tk9.0.3 Documentation > [incr Tcl] Package Commands, version 4.3.5 > local

### Tcl/Tk Applications | Tcl Commands | Tk Commands | [incr Tcl] Package Commands | SQLite3 Package Commands | TDBC Package Commands | tdbc::mysql Package Commands | tdbc::odbc Package Commands | tdbc::postgres Package Commands | tdbc::sqlite3 Package Commands | Thread Package Commands | Tcl C API | Tk C API | [incr Tcl] Package C API | TDBC Package C API

### NAME

itcl::local — 手続函数に局所的な対象を生成する　　　　 create an object local to a procedure

### 構文 SYNOPSIS

itcl::local className objName ?arg arg ...?

### 説明 DESCRIPTION

この local 命令は､現在呼出している枠組みに局所的な [incr Tcl] 対象を生成する｡呼出した枠組みが消え去る時､その対象は自動的に消去される｡この命令は手続函数に局所的な対象を生成する際に便利である｡　　　　 The local command creates an [incr Tcl] object that is local to the current call frame. When the call frame goes away, the object is automatically deleted. This command is useful for creating objects that are local to a procedure.

副作用として､この命令は､"itcl-local-xxx" と言う名前の変数を生成する､ここで xxx は生成された対象の名前である｡ この変数は呼出した枠組みが破壊される時を検出し､自動的に結合された対象を消去する｡　　　　　 As a side effect, this command creates a variable named "itcl-local-xxx", where xxx is the name of the object that is created. This variable detects when the call frame is destroyed and automatically deletes the associated object.

### 用例 EXAMPLE

次の実施例の中で､単純 "counter" 対象は手続函数 "test" 内部で使用される｡counter は局所対象として形成され手続函数が終了する度に消去される｡ 構築子/破壊子 に含まれる puts 宣言は､手続函数が呼出されるに従い現れたり去ったりする対象を表示する｡　　　　 In the following example, a simple "counter" object is used within the procedure "test". The counter is created as a local object, so it is automatically deleted each time the procedure exits. The puts statements included in the constructor/destructor show the object coming and going as the procedure is called.

    itcl::class counter {
        private variable count 0
        constructor {} {
            puts "created: $this"
        }
        destructor {
            puts "deleted: $this"
        }

        method bump {{by 1}} {
            incr count $by
        }
        method get {} {
            return $count
        }
    }

    proc test {val} {
        local counter x
        for {set i 0} {$i < $val} {incr i} {
            x bump
        }
        return [x get]
    }

    set result [test 5]
    puts "test: $result"

    set result [test 10]
    puts "test: $result"

    puts "objects: [itcl::find objects *]"

### KEYWORDS

class, object, procedure
Copyright © 1993-1998 Lucent Technologies, Inc.