[fpc-pascal] TThread descendant with public events
Sven Barth
pascaldragon at googlemail.com
Mon Nov 1 10:06:14 CET 2010
On 01.11.2010 09:57, Graeme Geldenhuys wrote:
> Hi,
>
> What is the rules regarding a TThread descendants and public events. I
> created a thread that has OnXXX events. These events are triggered in the
> Execute method of that event.
>
> Now my main event (which manages the application GUI) hooked into these
> event by implementing event handlers. Those event handlers take the data
> from the event and updates a StringGrid.
>
> Is this safe to do?
>
> Must the thread execute the event via a Synchronize() call, or is it now
> needed? The reason I'm not sure here, is because the thread doesn't actuall
> update the GUI component (stringgrid in this example) directly, it just
> triggers the event.
The code is still run in the thread's context, no matter whether the
code is in your TThread class or e.g. a global procedure. So you should
use Synchronize to trigger the event.
Regards,
Sven
More information about the fpc-pascal
mailing list