Re: Problem with GTK entry get_text function
| From: | Tom Rogers | Date: | Wed, 30 Mar 2005 05:51:08 +0000 |
| Subject: | Re: Problem with GTK entry get_text function | ||
| References: | 1 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-5701@lists.php.net to get a copy of this message | ||
Hi,
Wednesday, March 30, 2005, 6:22:51 AM, you wrote:
JC> Hi,
JC> I am having trouble accessing variables generated
JC> using 'while loop' for GTK Entry. I have pasted the
JC> code below which obviously doesnt work.I would be
JC> really thankful if anyone can help me OR suggest an
JC> alternative.
JC> <?php
JC> if( !extension_loaded('gtk'))
JC> {
JC> dl( 'php_gtk.' . PHP_SHLIB_SUFFIX);
JC> }
JC> $display = &new GtkWindow();
$display->>set_title('Uinque');
$display->>set_usize(640,480);
JC> $box = &new GtkVbox();
$display->>add($box);
JC> class abc
JC> {
JC> function main()
JC> {
JC> global $box;
JC> $x = 1;
JC> while ($x < 5)
JC> {
JC> global ${'merc'.$x};
JC> $GLOBALS[${'merc'.$x}] = &new GtkEntry();
JC> $box->pack_start($GLOBALS[${'merc'.$x}]);
JC> $GLOBALS[${'merc'.$x}]->set_text('merc'.$x);
JC> $GLOBALS[${'merc'.$x}]->show();
JC> $x++;
JC> }
JC> }
JC> function get_text()
JC> {
JC> global $merc1;
JC> $gettext = $merc1->get_text();
JC> echo $gettext;
JC> }
JC> }
JC> $abc = new abc;
$abc->>main();
JC> function gt()
JC> {
JC> global $abc;
JC> $abc->get_text();
JC> }
JC> $btn = &new GtkButton('Retrieve') ;
$btn->>show();
$btn->>connect('clicked','gt');
$box->>pack_end($btn);
$display->>show_all();
JC> Gtk::Main();
?>>
JC> __________________________________
JC> Do you Yahoo!?
JC> Yahoo! Small Business - Try our new resources site!
JC> http://smallbusiness.yahoo.com/resources/
Your globals I found confusing so I changed it to this and it works:
class abc
{
function main()
{
global $box;
$x = 1;
while ($x < 5)
{
$key = 'merc'.$x;
$GLOBALS[$key] = &new GtkEntry();
$box->pack_start($GLOBALS[$key]);
$GLOBALS[$key]->set_text('merc'.$x);
$GLOBALS[$key]->show();
$x++;
}
}
function get_text()
{
global $merc1;
$gettext = $merc1->get_text();
echo $gettext;
}
}
--
regards,
Tom