[Gambas-user] behaviour of Last + Timer events

Benoît Minisini gambas at ...1...
Mon May 11 16:29:42 CEST 2009


> 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.
>
> Regards
>
> Richard
>
>

The algorithm is the following:

When an event is fired:
- The current value of LAST is saved.
- LAST is set to the object that emitted the event.
- The event handler is called.
- LAST is set to the value saved initially.

So, if an event handler is called during another one, because you used WAIT, 
the value of LAST is not changed.

So you should not have any problem. But what are you doing exactly in "doing 
something else"?

-- 
Benoît




More information about the User mailing list