in reply to Dynamic Subroutines?

What I am trying to do is use the events that are defined in Win32::Gui. In my script I query a list and dump them into a ListView. Once they are in the ListView I want to be able to click on an element in the ListView and have its detail display in a Textfield. In order to do this I need to use the follow event:

ItemClick(ITEM) Sent when the user selects an item in the ListView; ITEM specifies the zero-based index of the selected item.

so in order to get the desired results I have to create a subroutine for every item in my ListView. When I code it up statically it works.

sub ResultView_ItemClick(2) { $Display->results->Text(${$List{2}}{message}); }
However when I use :
my $code = "sub ResultView_ItemClick($count) { $Display->results->Text +(${$List{$count}}{message});}"; eval $code;
when I am building my list whenever I click on an element I generate an error. When I run the code it seems that the GUI::Dialog reconizes that I created the subs but it throws an error "Undefined subroutine &main::ResultView_ItemClick"

Replies are listed 'Best First'.
Re: Re: Dynamic Subroutines?
by suaveant (Parson) on Mar 30, 2001 at 21:46 UTC
    Ahhh, yes... I would really suggest the Advanced Perl Programming book from O'Reilly. It cover similar things...

    You actually do not need a closure, you should simply be able to do the following:

    *ResultView_ItemClick = sub { $Display->results->Text(${$List{$_[0]}}{ +message}); }; ResultView_ItemClick(2);
    That should do what you want.. if I understand correctly.
    - Ant