I'm trying to retool to Perl from Ansi C (dabbled only slightly in C++ years ago.) I am writing an app that uses a database. I pull the needed data from the database at the beginning of Package MyFrame, and then attempt to handle an EVT_COMBOBOX, but can't seem to pass data to the event handler. I basically need to get the selected combo box entry to the event handler sub so that I can use it in the sub. How is this done? (I'm familiar with passing pointers in C. I think that "aliasing" may be analogous to that, but I don't know how it's done in Perl.) I've made a few vain attempts, but can't seem to find examples for Perl WxWidgets that apply. So far my code is simply in a proof-of-concept state (cut and paste from examples with a few adjustments of my own). So sub Combobox1action is generic and has nothing in it but place holding code. It does execute in its present state, but I'm at a stalemate with it. Below is the MyFrame package.

package MyFrame; use base 'Wx::Frame'; use Wx::Event qw(EVT_BUTTON EVT_COMBOBOX ); my $sth; my $tablename; my $sqlcommand; my @lessonnumber; my @lessonsimplename; my @lessontitle; my @startingpagenumber; my $nameargument; my $increment = 0; my $dbh = DBI->connect("dbi:mysql:*********", "root","*******") or die "Can't connect to MySQL database: $DBI::errstr\n"; $sqlcommand = "SELECT lessonstring, lesson_number, description, starti +ng_pagenumber FROM lesson_titles"; $sth = $dbh->prepare ($sqlcommand) or die "Cannot perform SQL INSERT: $DBI::errstr\n"; $sth->execute( ) or die "Cannot perform execute\n"; for ( $increment = 1; $increment <= 132; $increment++ ) { ( $lessonsimplename [ $increment-1 ], $lessonnumber[ $increment-1 + ], $lessontitle [ $increment-1 ], $startingpagenumber [ $increment-1 ] ) = $sth->fetchrow_array() +; } $sth->finish; $dbh->disconnect or warn "Disconnect failed: $DBI::errstr\n"; #for ( $increment = 1; $increment <= 132; $increment++ ) { # print ($lessonsimplename [ $increment ].": ".$lessontitle [ $incr +ement ]." p. ".$startingpagenumber [ $increment ]."\n"); #} sub new { my $ref = shift; my $self = $ref->SUPER::new( undef, # parent window -1, # ID -1 means any '********', # title &Wx::wxDefaultPosition, # defaul +t position [200, 200] # size ); my $panel = Wx::Panel->new( $self, # parent window -1, # ID ); my $button1 = Wx::Button->new( $panel, # parent window -1, # ID 'Click me 1!', # label [50, 20], # position &Wx::wxDefaultSize # default s +ize ); my $button2 = Wx::Button->new( $panel, # parent window -1, # ID 'Click me 2!', # label [50, 50], # position &Wx::wxDefaultSize # default s +ize ); my $button3 = Wx::Button->new( $panel, # parent window -1, # ID '*********', # label [50, 80], # position &Wx::wxDefaultSize # default s +ize ); my $combobox1 = Wx::ComboBox->new( $panel, -1, $lessonsimplename[ 0 ], [50, 110], [-1, -1], \@lessonsimplename, 0, &Wx::wxDefaultValidator, '' ); EVT_BUTTON( $self, $button1, \&Button1Click ); EVT_BUTTON( $self, $button2, \&Button2Click ); EVT_BUTTON( $self, $button3, \&Button3Click ); EVT_COMBOBOX( $self, $combobox1, \&Combobox1action ); return $self; } sub Button1Click { my( $self, $event ) = @_; $self->SetTitle( 'Button 1 Clicked' ); } sub Button2Click { my( $self, $event ) = @_; $self->SetTitle( 'Button 2 Clicked' ); } sub Button3Click { my( $self, $event ) = @_; $self->SetTitle( '*********' ); } sub Combobox1action { my( $self, $event ) = @_; $self->SetTitle( 'Combo box selected' ); }

Thanks.


In reply to Passing arguments to event handlers in WxPerl by pwn01

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.