Re: keeping track of the right instance od a class ?
| From: | firepages.com.au | Date: | Fri, 03 Jan 2003 09:45:36 +0000 |
| Subject: | Re: keeping track of the right instance od a class ? | ||
| References: | 1 2 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-2824@lists.php.net to get a copy of this message | ||
ThankYou! , that got me sticking
&'s everywhere till it worked :) (then
lost the fat) , my real app is a little different from my example but the
below eventually did the trick
/***in class B***/
function add_user_button($label,$function,&$obj){
$submit=& new GtkButton($label);
$submit->connect_object('clicked',array(&$this,_return_values),&$obj,$functi
on);
$this->pack_end($submit);
}
function _return_values($obj,$function){
$this->get_all_values();
$res=$this->results;
$obj->$function($res);
}
/*
I know I can do the above in one function , but then have problems
accessing variables form class B
i.e. this works in that it returns to the right function...
$this->get_all_values();//updates $this->values//
but $this->values; is no longer available ? - but the above combo of 2
functions works lovely ??
$submit->connect_object('clicked',array(&$obj,$function),$this->values);
Hard coding a value works fine
$submit->connect_object('clicked',array(&$obj,$function),'some value');
I just seem to lose the reference to class B
So I am going to stick to being happy that its just working :D
*/
/***in class A****/
$B->add_user_button('edit selected php.ini','_set_working_ini',$this);
/*..... and
function _set_working_ini($array){
$this->CWS=$array[0]['var'];
}
Cheers again.
Regards,
Simon Wheeler
firepages
----- Original Message -----
From: "Alan Knowles" <alan@akbkhome.com>
To: "firepage" <firepage@firepages.org>
Cc: <php-gtk-general@lists.php.net>
Sent: Friday, January 03, 2003 4:30 PM
Subject: Re: [PHP-GTK] keeping track of the right instance od a class ?
> firepage wrote:
>
> >Hi, sorry about the subject but I dont know how to explain...
> >
> >I have a class A that calls a function in class B, this function returns
a value to a function of class A
> >that all works in that a value is returned , but not I think to the same
instance... ?
> >
> >whatever is going on I cant do this $this->value=$value; with the
returned value.
> >I assume I need to be sending a reference to this instance of class A ?
> >
> >class A {
> >var $value;
> > function A (){
> > $this->value='';
> > $b=&new B();
> > $b->get_value('A_callback',$this);/*I tried &$this*/
> > echo $this->value;
> > }
> >
> > function
allback($value){
> > $this->value=$value;
> > /*$value exists and is returned as expected if I echo
> > $value*/
> > /* but $this->value; ($a->value;) is NOT being set*/
> > }
> >}
> >
> >class B{
> > function B(){
> >
> > }
> >
> > function get_value( $callback , $obj ){
> >
> ..........................................&$obj
>
> > $value="I want this returned";
> > $obj->$callback($value);
> > /*this is successfully calling $a->A_callback("I want this returned");*/
> > }
> >}
> >
> >$a=&new A;
> >
> >
> >I tried returning the object from class B but with the same results.
> >
> >Any pointers appreciated !
> >
> >Regards,
> >Simon Wheeler
> >firepages
> >
> >
> >
>
>
> --
> Can you help out?
> Need Consulting Services or Know of a Job?
> http://www.akbkhome.com
>
>
>
> --
> PHP-GTK General Mailing List (http://gtk.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
>