Version 5 of itcl::configbody

Updated 2007-01-12 14:24:25

[ Someone want to write up something about what this incr tcl command does?

If you think the answer below fulfils the above request please remove it and this text.


AW from the source code of itcl3.3:

 *    itcl::configbody <class>::<publicVar> <body>
 *
 *  Looks for an existing public variable with the name <publicVar>,
 *  and if found, tries to assign the implementation.  If <body> has
 *  the form "@name" then it is treated as a reference to a C handling
 *  procedure; otherwise, it is taken as a body of Tcl statements.
 *

As far as I understand it: if you assign a public variable a value with the itcl configure command (myclass configure -myvar Hello) then first the new value is assigned to that variable and afterwards the script in configbody is evaluated additionally.

It is also possible to define a config script for a variable when defining the variable: protected variable myvar hello {puts "this is the configscript of myvar"}

GWM at last it becomes vaguely less fog encrusted. When the program (or user) changes a public variable by use of the 'configure -<VARNAME> newvalue' option, then the configbody is called rather like a trace. So here is the simplest clear example I can conceive (this is not a competition).

  console show;  update idletasks
  package require Itcl
  itcl::class sampleconf { ;# a sample class with a single public variable
    public variable publicv ;# this var is adjusted using the configure -publicv...
    constructor {} { }
    method setpublicv {dn} { set publicv "$dn"   }
  }
   # create a sample instance of the class:
  set btn [sampleconf  h2]
   # add a configbody for publicv
  itcl::configbody sampleconf::publicv  {tk_messageBox -message "Publicv in $this was set to $publicv by a configure command."}
  h2 configure -publicv "A new Value"
  h2 configure -publicv "The same old Value"
  h2 setpublicv "A value which is not sent via the configbody"
  h2 configure -publicv "Another Value"

Note that the configbody applies to all instances of sampleconf, but that changing the value of publicv (by calling method setpublicv) does NOT call the cofigbody.


Category Command a part of the incr tcl object oriented package