[Gambas-user] How do I use tag property for a group of timers ?

Tobias Boege taboege at gmail.com
Sat Aug 17 17:03:39 CEST 2019


On Sat, 17 Aug 2019, nando_f at nothingsimple.com wrote:
> == A possible idea is ==
> If you have an array of struct wherein a member of struct is a timer
> then just add another parallel member that is your tag.
> 
> pseudo code:
> struct 
>    object <--> mytimer
>    string <--> mytag
> End
> 
> ...
> 
> myarray array[1...100] of struct
> 
> ...
> 
> myarray[17].mytag = "17"
> myarray[17].mytimer.start
> 

I'm pretty sure Vinode was aware of this possibility already. The problem
is that inside the Timer event handler, you only get a reference to the
Timer object that raised it. To get the tag that lives besides it in the
struct, you would have to iterate over the array, look for the struct that
contains the current timer and then you will have found the tag as well.
This is a lot of work for every tick of every timer.

The solution Bruce proposed to this is to encapsulate the timer and the
tag in a new class which captures and propagates the events of its
internal timer. This way, the entire object -- timer and tag -- raise
the event to the outside and all the data is immediately available in
the event handler.

Catching and raising events is something a struct cannot do. It has to
be a class.

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk


More information about the User mailing list