forcing variable (not command) substitution?
Posted by that_guy (that_guy), 25 July 2003Hi. I've made a scrolledframe that is populated with entryfields "on the fly" with field names/values from a database. The fields/values correspond to program flags "-c -f -l", and arguments. In the database, for each flag I'm also storing whether it's a short option or long(requiring an argument). If I have a short option, I want to create a checkbutton instead of an entryfield. So far all of this works. The problem now is just that I want to do something like
$entry configure -text $name -variable "$chost$name"
I'm using the values from the textfields and checkboxes to build up a string like "iperf -c --len 5", so later on I want to retrieve the state of the checkbutton from its variable. How can I force something like eval $"$chost$name" to work? If I use eval it will complain this is not a command. Thanks so much for any insight
So I found the subst command, unfortunately I also found out that TCL variables cannot have hyphens in them. I ran out of ideas as to how to do this nicely- so I ended up doing a regsub -all -- - on the name before defining a variable.
Posted by admin (Graham Ellis), 26 July 2003Tcl variables can include any special characters that you like includeing the hyphen, but you need to protect them from the interpretter by writing the variable name in curly braces. It is something I would suggest you don't do, but it is possible.
In the earlier part of your question, you are tying a variable who's name is $chost$name to your data entry box. You don't need to do any sort of eval on it as (as it correctly complains), it's not a command but a variable. At every point once you've built your GUI, it contains a copy of what's actually displayed in the entry box, and you can use it just as an ordinary variable - for example you could write
lappend mylist $"$chost$name"
if you wanted to add it to a list
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: firstname.lastname@example.org • WEB: http://www.wellho.net • SKYPE: wellho