GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
classvariable(n) TclOO Commands classvariable(n)


classvariable - create link from local variable to variable in class

package require tcl::oo
classvariable variableName ?...?

The classvariable command is available within methods. It takes a series of one or more variable names and makes them available in the method's scope; those variable names must not be qualified and must not refer to array elements. The originating scope for the variables is the namespace of the class that the method was defined by. In other words, the referenced variables are shared between all instances of that class.

Note: This command is equivalent to the command typevariable provided by the snit package in tcllib for approximately the same purpose. If used in a method defined directly on a class instance (e.g., through the oo::objdefine method definition) this is very much like just using:

namespace upvar [namespace current] $var $var

for each variable listed to classvariable.

This class counts how many instances of it have been made.

oo::class create Counted {
    initialise {
        variable count 0
    }
    variable number
    constructor {} {
        classvariable count
        set number [incr count]
    }
    method report {} {
        classvariable count
        puts "This is instance $number of $count"
    }
}
set a [Counted new]
set b [Counted new]
$a report
        → This is instance 1 of 2
set c [Counted new]
$b report
        → This is instance 2 of 3
$c report
        → This is instance 3 of 3

global(n), namespace(n), oo::class(n), oo::define(n), upvar(n), variable(n)

class, class variable, variable
0.3 TclOO

Search for    or go to Top of page |  Section n |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.