pwn01 has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|