Forum OpenACS Q&A: template::multirow upvar -- example of use?

Hi

I'm trying to use template::multirow -local -ulevel #[adp_level] upvar $photos_reference ad_photos and it just gives me 2 conflicting errors. The errors imply 2 impossibly conflicting things!

The multirow I'm trying to upvar seems like it should not exist when I issue the template::multirow call. If it does exist I get this error

variable "ad_photos:rowcount" already exists
    while executing
"upvar #5 ad_photos:rowcount ad_photos:rowcount ad_photos:columns ad_photos:columns"
Makes sense so far, I am not able to overwrite an existing local variable with the upvar.

Ok, if the local multirow does not exist before the call to template::multirow, I get this error

can't read "ad_photos:rowcount": no such variable
    while executing
"for { set i 1 } { $i <= ${ad_photos:rowcount} } { incr i } {
          upvar #5 ad_photos:$i ad_photos:$i
        }"
    ("uplevel" body line 3)
As we can see, the template::multirow upvar proc is trying to upvar all the rows using the rowcount. But the rowcount does not exist yet. (I get the first error if it does)

So has anyone used template::multirow upvar that can send me a sample of it's intended use? I'm trying to copy a local multirow datasource to the adp level. This seems like what I want yet I don't see how it could work properly either. I grep'd the source for all packages and could not find anywhere it's used.

Help! thanks.

Collapse
Posted by Lars Pind on
Tammy,

multirow upvar works the opposite way: It upvars a multirow from wherever it exists (typically the #[adp_level] stack frame) to your stack frame.

It can't do it the other way around, since that is the way Tcl's 'upvar' command works: It takes a variable from another stack frame and makes it available in your stack frame.

Btw, saying -local -ulevel #[adp_level] as you do above is equivalent to not specifying anything.

You can find multirow upvar used in packages/acs-templating/tcl/list-procs.tcl, which I added last week.

/Lars