📄 configbody.n
字号:
'\"'\" Copyright (c) 1993-1998 Lucent Technologies, Inc.'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\"'\" RCS: $Id: configbody.n 144 2003-02-05 10:56:26Z mdejong $'\".so man.macros.TH configbody n 3.0 itcl "[incr\ Tcl]".BS'\" Note: do not modify the .SH NAME line immediately below!.SH NAMEconfigbody \- change the "config" code for a public variable.SH SYNOPSIS\fBconfigbody \fIclassName\fB::\fIvarName body\fR.BE.SH DESCRIPTION.PPThe \fBconfigbody\fR command is used outside of an \fB[incr\ Tcl]\fRclass definition to define or redefine the configuration codeassociated with a public variable. Public variables act likeconfiguration options for an object. They can be modifiedoutside the class scope using the built-in \fBconfigure\fR method.Each variable can have a bit of "config" code associate with itthat is automatically executed when the variable is configured.The \fBconfigbody\fR command can be used to define or redefinethis body of code..PPLike the \fBbody\fR command, this facility allows a class definitionto have separate "interface" and "implementation" parts.The "interface" part is a \fBclass\fR command with declarationsfor methods, procs, instance variables and common variables.The "implementation" part is a series of \fBbody\fR and\fBconfigbody\fR commands. If the "implementation" partis kept in a separate file, it can be sourced again andagain as bugs are fixed, to support interactive development.When using the "tcl" mode in the \fBemacs\fR editor, the"interface" and "implementation" parts can be kept in thesame file; as bugs are fixed, individual bodies can behighlighted and sent to the test application..PPThe name "\fIclassName\fB::\fIvarName\fR"identifies the public variable being updated.If the \fIbody\fR string starts with "\fB@\fR", it is treatedas the symbolic name for a C procedure. Otherwise, it istreated as a Tcl command script..PPSymbolic names for C procedures are established by registeringprocedures via \fBItcl_RegisterC()\fR. This is usually donein the \fBTcl_AppInit()\fR procedure, which is automatically calledwhen the interpreter starts up. In the following example,the procedure \fCMy_FooCmd()\fR is registered with thesymbolic name "foo". This procedure can be referenced inthe \fBconfigbody\fR command as "\fC@foo\fR"..CSintTcl_AppInit(interp) Tcl_Interp *interp; /* Interpreter for application. */{ if (Itcl_Init(interp) == TCL_ERROR) { return TCL_ERROR; } if (Itcl_RegisterC(interp, "foo", My_FooCmd) != TCL_OK) { return TCL_ERROR; }}.CE.SH EXAMPLEIn the following example, a "File" class is defined to representopen files. Whenever the "-name" option is configured, theexisting file is closed, and a new file is opened. Note thatthe "config" code for a public variable is optional. The "-access"option, for example, does not have it..CSclass File { private variable fid "" public variable name "" public variable access "r" constructor {args} { eval configure $args } destructor { if {$fid != ""} { close $fid } } method get {} method put {line} method eof {}}body File::get {} { return [gets $fid]}body File::put {line} { puts $fid $line}body File::eof {} { return [::eof $fid]}configbody File::name { if {$fid != ""} { close $fid } set fid [open $name $access]}## See the File class in action:#File xx configure -name /etc/passwdwhile {![x eof]} { puts "=> [x get]"}delete object x.CE.SH KEYWORDSclass, object, variable, configure
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -