Is there some way of implementing this in Itcl.
-Amit
------------------------------------------------------------------------------
itcl::class visInfo {
constructor {args} {
if { [catch {
if { [$args isa visInfo] } {
#Copy Constructor here
foreach vName [$this info variable] {
set realName [string range $vName [expr {[string last "::"
$vName]+2}] end]
configure -$realName [$args cget -$realName]
}
}
} err] } {
eval configure $args
}
}
public variable name ""
public variable x ""
public variable y
public variable fontSize ""
public variable zorder ""
}
--------------------------------------------------------------
But note, that it's (nearly sure) slower method, becouse interpreter
needs to inspect and process some data before copying value and your
method gives ready to use instructions - what to copy, where from and
where to.
--
Pozdrawiam! (Greetings!)
Googie
> --------------------------------------------------------------
> let me know if there is a cleaner implementation
In addition to what Googie said already, you could ommit the "catch",
and use Itcl's introspection capabilities more intensively:
itcl::class visInfo {
constructor {args} {
if {[llength $args] == 1 && [$args isa visInfo]} {
foreach v [$args info variable] {
set [namespace tail $v] [$args info variable $v -value]
}
} else {
eval configure $args
}
}
public {
variable name ""
...
}
}
This works not only for public variables, but also for private and
protected ones. But note that it does not make deep copies of member
objects - it just copies string references...
Eckhard