GTK2::TieScalar and DBI stuff



Hi all. I'm back.

I'm having trouble getting GTK2::TieScalar to work.
I have a sub that loads up data ( currently a single record ) into @data:

- - -

sub getRecords {
   
    # Prepare statement for execution
    my $sth = $dbh->prepare("select " . join (", ", @fields)  . " from BillsReceived where BatchNo=1");
   
    # Execute statement
    $sth->execute or die "Couldn't execute statement! " . DBI::err_str;
   
    my $ctr = 0;

    while (my $row = $sth->fetchrow_hashref) {
        push @{ $data }, $row;
    }
   
    # Disconnect database connection
    $dbh->disconnect;
   
}

- - -

This works fine.
Then I have a sub that ( attempts to ) tie the values in @data to widgets in my window:

- - -

sub InitWidgets {

    use Gtk2 -init;
    use Gtk2::GladeXML;
    use Gtk2::SimpleList;
    use Gtk2::TieScalar;
    use Gtk2::TieArrayRef;
   
    # TODO: How to trigger an exception if no window of this name!
    $glade = Gtk2::GladeXML->new($gladefile, 'MultipleSimple');

# Later....   
#    $l = Gtk2::SimpleList
#            ->new_from_treeview($glade->get_widget('singleList'),
#                                                    'Single Select' => 'text');
#    my @data = ""> #    $l->set_data_array([ @data ]);
   
    my $counter = 0;
   
    foreach my $field (@fields) {
       
        my $widget = $glade->get_widget($field);
       
        print "Current field is $field \n and has value " . $data->[$recnum]->{$field} . "\n";
        print "Current widget value is " . $widget->get_text . "\n";
       
        # Tie the value stored in field $field, from the $recnum-th record of the $data arrayref to the widget
        $fieldties[$counter] = Gtk2::TieScalar->create(\$data->[$recnum]->{$field}, $widget);
      
        print "Current field is $field \n and has value " . $data->[$recnum]->{$field} . "\n";
        print "Current widget value is " . $widget->get_text . "\n";
      
        $counter ++;
       
    }
   
    $glade->get_widget('btnShowVars')
            ->signal_connect('pressed' => \&ShowVars);
    $glade->get_widget('btnNextRecord')
            ->signal_connect('pressed' => \&getNextRecord);

    $glade->signal_autoconnect_from_package();
       
}

- - -

At the point just before the:
$fieldties[$counter] = Gtk2::TieScalar->create(\$data->[$recnum]->{$field}, $widget)
line, the value in $data->[$recnum]->{$field} is correct. Immediately after this line, $data->[$recnum]->{$field} has no value. The widget also has no value. I assume I'm doing something wrong, but for the life of me, I can't tell what.

Any clues?

Dan

--
sig Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: dkasak nusconsulting com au
website: http://www.nusconsulting.com.au
Title: CanIt Vote for ID 37414

The following links have been placed here by the NUS Consulting internal spam filter and are for use by NUS Consulting staff only.
Please ingore these links.
Spam
Not spam
Forget previous vote


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]