Re: What's the magic to using Incr Tcl
- From: Andrew Falanga <af300wsm@xxxxxxxxx>
- Date: Fri, 29 Jun 2007 08:51:37 -0700
On Jun 29, 9:41 am, Troy.Tan...@xxxxxxx wrote:
You probably need to either qualify the commands with the itcl::
namespace:
itcl::class myClass {...}
or import the itcl commands like so:
namespace import ::itcl::*
You can make sure Itcl is loaded and whether you need to do this by
looking at the result of the following commands:
info commands class
info commands itcl::class
Some (early?) versions of Itcl I used didn't require the namespace
import. I never figured it out - whether it was my installation, or
some change to the Itcl package - but some installations worked with
just a package require Itcl, some didn't. I'd guess the tutorials
were written where the import was not necessary.
Troy
On Jun 29, 10:01 am, Andrew Falanga <af300...@xxxxxxxxx> wrote:
Hi,
I'm trying to learn to use the [incr Tcl] package and I seem to be
having some difficulty. I've downloaded a tutorial of sorts that I
found a link to from the main [incr Tcl] web site. It's called,
"Object-Oriented Programming with [incr Tcl]." I've figured out that
I must use a "package require Itcl" in my script to load the package.
however, then the interpreter bails saying that the command "class" is
unknown. I've also tried "Class" although none of the examples in
this tutorial use an upper case C in the word class.
So, after one brings in the functionality with "package require", how
does one actually use the package? I'm also using the manual pages on-
line fromhttp://www.tcl.tk/man/itcl3.1/index.htmlandthere it is
mentioned that the command name for class is "class". So, below is
the very simple script I've put together to familiarize myself with
this package, please tell me what I'm doing wrong.
Oh, nearly forgot, in case it's important, I'm using ActiveState TCL
on Windoze. Is it possible I'm getting the wrong package?
Thanks,
Andy
puts [package require Itcl]
Class myClass {
variable int
constructor { i } {
puts "C-tor for myClass called: setting int to $i"
set int $i
}
destructor {
obliterate
}
method SetInt { i } {
set int $i
}
method ShowInt { } {
puts $int
}
method obliterate { } {
puts "inside destructor: obliterate"
unset int
}
}
myClass mc1 78
mc1 ShowInt
mc1 SetInt 33421
mc1 ShowInt
delete object mc1
Thanks everyone. At least I wasn't too far off.
Andy
.
- References:
- What's the magic to using Incr Tcl
- From: Andrew Falanga
- Re: What's the magic to using Incr Tcl
- From: Troy . Tanzer
- What's the magic to using Incr Tcl
- Prev by Date: Re: What's the magic to using Incr Tcl
- Next by Date: Re: A widget for the user's editor of choice
- Previous by thread: Re: What's the magic to using Incr Tcl
- Next by thread: Re: What's the magic to using Incr Tcl
- Index(es):
Relevant Pages
|