On Monday 23 February 2004 18:31, Michael Ragsdale generously enriched virtual
reality by making up this one:
..
Hi Mike,
> my $ent =$right->Entry(-width=>8,-background=>'white')->pack(-side=>'left');
^line 1
> my $go = $right->Button(-text=>'Get
> Data',-command=>sub{compute($ent)})->pack(-side=>'top');
^line2
> MainLoop();
>
> sub compute {
> my $data_source = "DBI:Oracle:host=*****.****.***.***;sid=****";
>
> my $dbh = DBI->connect($data_source,"*************","**********")
> or die "Cannot connect to $data_source; $DBI::errstr\n";
>
> my $sth = $dbh->prepare(qq(SELECT cuid, cuname
> FROM fcustomer
> WHERE cuid = ?)) or die "Cannot prepare
> query: $DBI::errstr\n";
>
> $sth->execute($_[0]) or die "Cannot execute query: $DBI::errstr\n";
^line 3
>
> my @row = $sth->fetchrow_array;
>
> $id_txt->configure(-text=>$row[0]);
> $name_txt->configure(-text=>$row[1]);
> $sth->finish();
> $dbh->disconnect;
> }
>
> When I enter an id in the Entry widget and click on the button, I get the
> following error message:
..
> I've tried to dereference $ent by sending $$ent but that didn't work either
> and gave me the error of "not a SCALAR reference". Any suggestions
> welcome.
In line 1 you create an Entry Widget object $ent.
In line 2 you pass that object to sub compute when the button is pressed.
And in line three you expect a number (whatever was enterd into $ent).
This
sub compute {
my $msg = " You passed ".$_[0]->get()." to compute.";
$main->messageBox(-message=>"$msg", -type=>'OK',-icon=>'info');
}
works.
However, dont pass the object - pass a refernece to it in line 2, like:
my $go = $right->Button(-text=>'Get Data',-command=>sub{compute(\
$ent)})->pack(-side=>'top');
and use $$_[0]->get in compute
OR:
associate a (global) variable with the entry widget in line 1 like:
my $entryvar;
my $ent =$right->Entry(-width=>8,-background=>'white', - textvariable => \
$entryvar)->pack(-side=>'left');
This way you allways end up having the actual value shown in $entryvar.
You get a new global, but you dont have to pass an object (or a reference to
one) if you dont need to for other reasons.
HTH,
Wolf
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>