I crave your indulgence as I try to understand what is happening here.
In the following code it would appear that the sub LoadDS is being called as the widget is created, rather than ONLY when the arrow on the drop-down list is clicked. This means that when it is called $self->{_dslist} is as yet undefined and so I get an error when I try to call the insert method on that object. Can somebody suggest a work-around?
My thought was to see if $self->{_dslist} has been defined and just return if it hasn't. Is that a valid way of handling it?
package datasource_ui; use strict; use Tk; use Tk::BrowseEntry; use Data::Dumper; sub new { my ($self, %arg) = @_; bless { _dbh => $arg{dbh}, _nbpage => $arg{nbpage}, _dslist => '', _dsSrcName => '', }, $self } sub draw { my ($self) = @_; $self->{_nbpage}->Label( -text => 'DataSource', -justify => 'right', -width => '20' )->grid( $self->{_dslist} = $self->{_nbpage}-> +BrowseEntry( + -variable => \$self->{_dsSrcName}, + -browsecmd => , + -listcmd => $self->LoadDS, + -width => '20', + ), -sticky => 'w', -pady => '20' ); return; } sub LoadDS { my ($self) = @_; print "start of LoadDS\n\n"; print Dumper $self; my ($id, $datasource, $ds_desc, $ds, @dss); my $SQL = "SELECT id, sourcename, sourcedesc FROM datasource"; my $sth = $self->{_dbh}->prepare($SQL); $sth->execute; while(( $id, $datasource, $ds_desc ) = $sth->fetchrow_array ) { $ds = "$datasource $ds_desc"; push @dss, $ds; } $self->{_dslist}->insert('end', @dss); return; } 1;
In reply to OO Perl & Tk - problem with callbacks. by jdtoronto
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |