Hi all

I am progressing with my project quickly, but have hit a problem that I cant seem to work out.

I am reading in a text file, and creating several buttons on the fly. This is a very simplistic version of the code:

==========

$win->AddButton(
        -name           =>   $configdata{name},
        -onClick        =>   sub { button_click($configdata{name}) }
        );

sub button_click(
        print "button clicked - $_[0]\n";
        );

==========

Printing out debug info as I go through the button creations shows that I am passing the correct $configdata{name} to the -onClick event parameter per created button, but when I run the program and click on a button, I always end up being shown that I clicked the last button I created, no matter which button I click.

If i undef %configdata after I have finished creating the buttons, and run the normal loop, my button_click() subroutine gets called, but without anything being passed to it.

Its like "$configdata(name}" is being expanded/substituted when I actually press the button (using the last $configdata{name} value from the button creation stage), rather than the parameter being expanded/substituted and stored when i create the button. If I undef the %configdata, nothing is being returned. If I dont undef it, I always get the ID of the last button I created. Infuriating, to say the least.

I need to use the -onClick events because the buttons I am creating are loaded from a text file, and all -onClick events go to the samer subroutine which deal with them all.

This is being run on ActiveState Perl 5.8.815 (if that helps any!)

Does anyone have any idea what I am doing wrong? I have been sitting here for 3 hours banging my head against this, and I am losing my will to live.

Steve

Reply via email to