kind of been there, done that, banged my head against it for several hours :)

I assigned the "name" to a temp variable, and used that

        my $name = $configdata{name};

then used

        -onClick => Button_Clicked($name)

http://sourceforge.net/mailarchive/message.php?msg_id=14457436


Perl Rob wrote:
Hi all,
Are you ready for this one? :) Let's see if I can even explain what I'm trying to do... I'm attempting to dynamically create buttons that use the -onClick option to go to a subroutine that is passed the name of the button. Why am I doing this, you ask? Well, since I don't know the name of the button at the time of its creation, I can't have an OEM event handler for it. Below is a code snippet that might explain it better. The problem comes on line 7 when I try to pass the name of the button (stored in $_ ) to the subroutine. I just can't get $_ to persist when the subroutine is called later: ############################################# foreach ( @button_names ) {
    $main->AddButton(
                   -name    => $_,
                   -size    => [251,35],
                   -pos     => [0,$y],
                   -text    => $_,
                   -onClick => sub { Button_Clicked ( $_ ) },
    );
    ++$y;
}
sub Button_Clicked {
     print "Your name is " . $_;
}
############################################# There just has to be a way to DWIM, but I've read perlsub over and over again without figuring it out. How can I pass the name of the button to the subroutine successfully? Thanks,
Rob


------------------------------------------------------------------------

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


------------------------------------------------------------------------

_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
http://perl-win32-gui.sourceforge.net/

Reply via email to