#
# tcl 8.4.1 / itcl3.2 / tested on windows xp
#
# how to parse args in parent before they are parsed in child
# usage of init code fragment
#
# constructor args ?init? body
foreach classid { parent child } {
# avoid to delete already deleted classes
if { [find classes $classid] != "" } {
delete class $classid
}
}
class parent {
public variable parent_a "";
public variable parent_b "";
constructor { args } {
puts stdout "parent this -$this- args -$args-"
eval configure $args
# check value of parent_a
if { $parent_a == "" } {
puts "--> bad parent_a"
}
}
}
class child {
inherit parent
public variable child_a
# pass arguments in an init code fragment
constructor { args } {eval "parent::constructor $args" } {
puts stdout "child this -$this- args -$args-"
eval configure $args
}
}
child testobj -child_a "val_child_a" -parent_a "val_parent_a"No, this should be implemented via itcl chain command.David
See also incr Tcl

