[Gambas-user] behaviour of Last + Timer events

Fabien Bodard gambas.fr at ...626...
Sun May 10 17:37:14 CEST 2009


Last is defined by the control that raise the event ... but it's a
global variable so if the timer raise during antother event subroutine

you will have this kind of problem ... the only way is to save the
last value in a local variable.


Dim MyLast as Object

MyLast = Last




2009/5/10 Doriano Blengino <doriano.blengino at ...1909...>:
> 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."
>
>
> ------------------------------------------------------------------------------
> The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
> production scanning environment may not be a perfect world - but thanks to
> Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
> Series Scanner you'll get full speed at 300 dpi even with all image
> processing features enabled. http://p.sf.net/sfu/kodak-com
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>




More information about the User mailing list