Re: PHP4 Object Issues.
| From: | Tom Rogers | Date: | Tue, 02 Aug 2005 22:58:37 +0000 |
| Subject: | Re: PHP4 Object Issues. | ||
| References: | 1 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-6127@lists.php.net to get a copy of this message | ||
Hi,
Wednesday, August 3, 2005, 5:18:17 AM, you wrote:
PBC> I know it is not a question to be placed here, but with GTK we really
PBC> use all the advanced procedures of PHP, in other places most people dont
PBC> even know its possible to do.
PBC> The problem is:
PBC> I have a object variable that stores the current selected node of a
PBC> Ctree Object, whenever a user clicks on it, the node is stored.
PBC> Somewhere in the program, I need to add a new field, and i use the node
PBC> as the parent node for the new one.
PBC> The problem i'm having is about crossing objects thru the execution
PBC> flow, and using a object variable from a function within this object,
PBC> but being called from outside. The variable in question appear to be
PBC> null, the code exemple shows my problem:
PBC> The Function atached to the select event:
PBC> function selecionar($node, $id) {
PBC> global $projeto;
$data = $this->>ctree->node_get_row_data($node);
PBC> $this->node_selecionado = $node; // this is the variable i need
PBC> to store
PBC> }
PBC> The Function that uses this variable:
PBC> function add_toolbox($objeto) {
PBC> $objptr =
$this->>ctree->insert_node($this->node_selecionado,null,array("N",$objeto
->>nome,$tipo),0,null,null,null,null,false,false);
$this->>ctree->node_set_row_data($objptr,array($this->objeto_pai,$objeto)
PBC> );
PBC> }
PBC> Here, the variable is ALWAYS null, but when i print it from other
PBC> function it is ok, anyone had this problem before?
PBC> The function add_toolbox is called always from a main object, this two
PBC> functions are from a object called toolbox, so they would be able to
PBC> share this variable.
PBC> Thanks
PBC> Piero
PBC> Obs: Maybe php has context issues with objects?
What I do to overcome this is to store any data like that inside the
actual gtk widget with
$this->ctree->set_data('current_node',$node);
$node = $this->ctree->get_data('current_node');
Although $this suffers during event calls the widget data survives.
You could also use the window object that holds the ctree object, in
my case it is a GtkVBox.
--
regards,
Tom