> I'm trying to get a handle on how variables are really handled in Tcl.
>
> Here is what I think I know:
> All variables are considered local unless specified otherwise.
> Widget variables are global and can be access in a procedure via the
> global command. i.e. Global var1,var2
> All variables are persistent unless unset.
>
> My question is: How do you access a variable created in another
> procedure? Does upvar have something to do with this? Is there some
> command other than set to declare a variable global?
Only global variable are persistent. Variables created within
a proc that are not declared global can be considered "on the stack."
Meaning they will be gone once the proc ends unless they are referenced
somewhere else.
If you don't want to use globals, you can use namespace variables
which will persist as well, but they are encapsulated within a namespace.
Try something like this in your init or main proc:
namespace eval ::my_program {
set ::my_program::data_list [list your list here]
}
Now, from any other proc, you can reference this variable by
using its fully-qualified path name. IE:
puts "data_list = $::my_program::data_list"
The easiest way is probably just to global it though. I usually
make a single array that I keep all of my global info in. Visual Tcl
itself has a single vTcl parray that holds all of its data. You can
try:
global mydata
set mydata(data_list) [list your list here]
set mydata(other_var) "more data"
etc...
Then, anytime you want information from the array, you just have
to global the one variable to get it. Hope that helps! 0-]
Damon
-------------------------------------------------------
This SF.Net email is sponsored by Sleepycat Software
Learn developer strategies Cisco, Motorola, Ericsson & Lucent use to deliver
higher performing products faster, at low TCO.
http://www.sleepycat.com/telcomwpreg.php?From=osdnemail3
_______________________________________________
vtcl-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/vtcl-user