Esteemed monks,

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

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.