[Gambas-user] behaviour of Last + Timer events

Doriano Blengino doriano.blengino at ...1909...
Sun May 10 09:02:02 CEST 2009


richard terry ha scritto:
> I got caught recently with a bug - many many weeks to uncover it, until I did 
> by random chance - a mix-up of what actually was 'Last'. So my question 
> basically is how Gambas determines what is 'Last'.
>
> I often use 'Last' in subroutines where I may have several controls which are 
> the same, and I have a common group eg say combo1,2,3, , where the group name 
> is say my_combos where each control has a tag, here lets 
> say "one", "two", "three"
>
> The code could be
>
> public sub my_combos_click()
>
> Select case last.tag
>      case "one"
> 		do somthing
>     case "two"
>                do something
>     case "three"
>               do something
> end select	
>
> As a result of whatever code I have in 'do something' I may then again 
> reference Last:
>
> something else = Last.text
>
> end 
>
>
> Now, what was happening in my program that on the main form - not the form 
> that I had the bug on -  I had a timer, which was firing every 10 minutes. 
> when my program crashed unexpectedly at one point, I inspected the properties 
> and found that the 'Last' referenced had ceased to be the 'Last' in my 
> subroutine, but had become the 'Last' control that fired an event - suddenly 
> the Timer on another form.
>
> As it turned out when I checked my code - it was my fault anyway - faulty 
> code, but it made me want to ask the question about how Gambas defines what 
> is Last. Seems to be a system-wide property - not just the last thing on a 
> particular form.
>
> Any observations/comments.
>   
Just a supposition...

an event handler like my_combos_click() should never be interrupted by 
an event, as long as... you don't use the WAIT instruction or some other 
calls to fiddle with the event system. So, if you didn't do anything 
like that, then it is a gambas "feature"... (gentle term for not saying 
"bug").
If you did some event fiddling, then you carry some more responsibility, 
but still I think there is some gambas feature involved.

Anyway, you can try to solve by saving LAST into a local variable, and 
then refer always to that local variable. May be it works, may be not...

It would be interesting to hear Benoit, to know wether LAST is a global 
variable or a local one, pushed on the stack before invoking an event 
handler.

Regards,

-- 
Doriano Blengino

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





More information about the User mailing list