Jean-Yves F. Barbier ha scritto:
> Doriano Blengino a écrit :
>   
>> Jean-Yves F. Barbier ha scritto:
>>     
>>> Hi list,
>>>
>>> Is there an equivalent to Python 'self' into GB?
>>>
>>> i.e. into a proc:
>>> TreeView1_MouseDown()
>>>    self.Enable = TRUE
>>> instead of
>>>    TreeView.Enable = TRUE
>>> END
>>>
>>>   
>>>       
>> This is LAST. But beware, it is the current sender of an event, not 
>> 'self'. There is also ME, which is the current instance of a class. From 
>> your example it is not clear what you mean, because it is a little 
>> nonsense. To clarify, take a form with a button1 on it. if you write:
>>
>>     public button1_click()
>>       last.x += 10
>>     end
>>
>>
>> the button will shift to the right every time you click it. If you write
>>
>>     public button1_click()
>>       me.x += 10
>>     end
>>
>>
>> the form will shift, not the button.
>>
>> I think (and hope) this is what you needed. Regards,
>>     
>
> I guess so: my purpose is to have a shortcut (some procs have very long names)
> into procs they "own" (otherwise, GB wouldn't know to which object apply the 
> command)
>   
Perhaps you are talking about event handlers? Beware that they are 
different from normal methods... but you will see by yourself.
> In my example proc is about TreeView1 object, so following what you said, 
> LAST.Enable = TRUE will be applied to TreeView1 BUT will it be applied to 
> another
> object I could reference into this proc=>
>
> i.e.:
> TreeView1_MouseDown()
>   TextBox2756.Text = "xxxxxxx"
>   LAST.Enable = TRUE   => does it apply to TreeView1 or TextBox2756 ?
> END
>   
applies to TreeView1 -------------^

I see your ideas are not clear. In the above subroutine LAST refers to 
the object which raised the event - presumably TreeView1 when you 
pressed a mouse button on it. But you can make several objects call the 
same event handler:

    ANewButton = new Button(me) as "TreeView1"   ' just to explain...

After that declaration, if you click that button, TreeView1_MouseDown 
will be called, and the same will happen if you click on TreeView1 (two 
different objects call the same event handler). But in the first case 
LAST will refer to ANewButton, in the second it will refer to TreeView1. 
That's all - no other meanings can be attached to LAST, and its life 
ceases when the subroutine (i.e., event handler) ceases. LAST is a 
global variable, so gambas will let you access it even when such a thing 
would be wrong; it makes sense only when referring to "the object which 
raised this singular event I am managing now".

Regards,

-- 
Doriano Blengino

"Listen twice before you speak.
This is why we have two ears, but only one mouth."


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to