[Gambas-user] Using a timer and Last

Doriano Blengino doriano.blengino at ...1909...
Sat Jan 1 10:34:25 CET 2011


richard terry ha scritto:
> Hi List
>
> I've a couple of timers on different forms, which I need to auto-update some 
> stuff periodically.
>
> What's the theory with Last and timers.
>
> for example say my program is executing a subroutine which uses Last, but at 
> that instance the timer fires and becomes Last, can things go wrong?
>
> Can just the Public = False property of the timer, mean it then cannot be the 
> Last event to fire?
>   
Hi Richard, happy new year.

I think that there is no need to worry: a timer event is just as any 
other one, only it is fired without user intervention.

There is a single internal main loop, in gambas, which collects events 
and dispatches them, one at a time, to the relevant handler. Just before 
invoking the handler, the LAST variable is set. A gambas subroutine is 
never interrupted, so the LAST variable remains untouched (unless you 
modify it yourself). To be more precise, the LAST variable is saved (in 
a stack, I believe), then set to the relevant value, then the handler is 
called, then LAST is restored. As long as you avoid to use WAIT, nothing 
can corrupt LAST (apart from your own program). The fact that LAST is 
saved onto a stack, and restored afterwards, should keep you safe even 
when you use WAIT in a handler.

About the Public property, I don't understand. The meaning of "Public" 
should only be relevant to the compiler, not to the runtime - "Public" 
should not be a property, but simply a declarative switch. May be that 
gambas uses the properties mechanism for simplicity, in order to allow 
you to declare something public using the GUI.

Anyway, you should simply consider that, inside an event handler, LAST 
always refers to the control which raised the event. Stop. For added 
safety, if and when you use WAIT in a handler, you could save LAST in a 
local variable, and restore it after the WAIT; but I really think it is 
not necessary.

Regards and cheers,

-- 
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