RE: [PHP-GTK] "Call to a member function on a non-object in C:\......."

From: Date: Fri, 21 May 2004 16:19:42 +0000
Subject: RE: [PHP-GTK] "Call to a member function on a non-object in C:\......."
References: 1  Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-4541@lists.php.net to get a copy of this message
$delete->connect_object('clicked', 'delete_message', $clist); function delete_message($clist) { $row = $clist->selection[0]; $get_msg_id = $clist->get_text($row, 0); echo $get_msg_id; } > -----Original Message----- > From: Rhys Campbell [mailto:rhys.campbell@da-systems.co.uk] > Sent: 21 May 2004 16:52 > To: PHP-GTK Mailing List (E-mail) > Subject: RE: [PHP-GTK] "Call to a member function on a non-object in > C:\......." > > > Well here's the code. There's a few include files but there's > nothing wrong with them as far as I know. This code work but is a > work in progress so will not be 100% perfect. Thanks! > > <?php > > require('commonfunctions.inc'); // include file for common functions > require('selectfromclist.php'); > require('sortclist.php'); // function to sort the clist in this file > > > function refresh_clist() > { > } > > function sent_messages() > { > require('odbc.inc'); // include file for db connectivity > $query = "SELECT msg_id, msg_ref, message, to, fromsys, state > FROM message_record"; > $window = &new GtkWindow; > $windows['Sent Messages'] = $window; > $window->set_name('query_window'); > $window->connect('delete-event', 'delete_event'); > $window->connect('destroy', 'destroy'); // connect event with function > $window->set_policy(false, true, false); > $window->set_title('Sent Messages'); > $window->set_position(GTK_WIN_POS_CENTER); // set position > relative to top left corner > $window->set_usize(500, 350); // set window size > $box1 = &new GtkVBox(); > $window->add($box1); > //frame displaying entered sql query > $frame = &new GtkFrame('Sent Messages'); > > $box1->pack_start($frame,false); > $label = &new GtkLabel("Sent messages: S = Sending, R = Received"); > $frame->add($label); > //frame displaying clist with the query result > $frame = &new GtkFrame('Sent Messages'); > $box1->pack_start($frame,true); > //we'll display the result with scrollbars > $scrolled_win = &new GtkScrolledWindow(); > $scrolled_win->set_border_width(5); > $scrolled_win->set_policy(GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); > $frame->add($scrolled_win); > /*here we deal with the result. If odbc_exec called with the > query entered in main window, return a result we can display clist > */ > if ($result = odbc_exec($odbc, $query)) > { > /* > at first, keys array contains the names of columns > */ > if ($data = odbc_fetch_array($result)) > { > $i=0; > $keys = array(); > while (list($key,$val) = each($data)) > { > /*if (/*$i%2)*/ $keys[]=$key; > $i++; > } > } > /* > now we can prepare the clist, keys are the titles of columns and > the number of columns is equal to the number of keys > */ > > $clist = &new GtkCList(count($keys), $keys); > $clist->connect('click_column', 'clist_click_column'); > //we sets the auto_resize for each column > for ($i=0;$i<count($keys);$i++) > $clist->set_column_auto_resize($i, true); > $scrolled_win->add($clist); > /* > now the data from result > we get the data from each row to row_data array and then we > append this array to the clist as a new row > */ > do > { > $clist->append($data); > }while($data = odbc_fetch_array($result)); > } > > $button = &new GtkButton('Refresh'); > $button->connect('clicked', 'refresh_clist'); // destroy php instance > $delete = &new GtkButton('Delete'); > $delete->connect('clicked', 'delete_message'); > $box1->pack_start($button, false); > $box1->pack_start($delete, false); > $button->set_flags(GTK_CAN_DEFAULT); > $button->grab_default(); > $window->show_all(); > } > > sent_messages(); // call function to display messages window > Gtk::main(); > > ?> > > -----Original Message----- > From: dpgirago@mdanderson.org [mailto:dpgirago@mdanderson.org] > Sent: 21 May 2004 16:45 > To: php-gtk-general@lists.php.net > Subject: RE: [PHP-GTK] "Call to a member function on a non-object in > C:\......." > > > Perhaps best to post the offending code. Don't know about making a > variable's scope permanently global. Probably wouldn't be good for data > integrity, though. Anyone else have an idea about this? > > dave > __________________________________________________________________ > _____________________________________ > > Yes I tried using globals but I get the same error > > function delete_message() > { > $row = $GLOBALS['clist']->selection[0]; > $get_msg_id = $GLOBALS['clist']->get_text($row, 0); > echo $get_msg_id; > } > > A note aside, I find it irritating having to declare globals in > functions, > no way to set it to global on declaration? > > -----Original Message----- > From: dpgirago@mdanderson.org [mailto:dpgirago@mdanderson.org] > Sent: 21 May 2004 16:19 > To: php-gtk-general@lists.php.net > Subject: Re: [PHP-GTK] "Call to a member function on a non-object in > C:\......." > > > Rhys, > > To use my previous example within a function, you need to access the > object through the GLOBALS array... > > $row = $GLOBALS['cListPatientID']->selection[0]; > $selectedPID = $GLOBALS['cListPatientID']->get_text($row,0); > > > > "Call to a member function on a non-object in C:\......." > > -- > PHP-GTK General Mailing List (http://gtk.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.gtk.general (#4541) next »