Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-11

TThread descendant with public events

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

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.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net:8080/fpgui/

Reply by email

Sven Barth
to Graeme Geldenhuys
Graeme Geldenhuys wrote 16 lines
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

Reply by email

Graeme Geldenhuys
to Sven Barth: The code is still run in the thread's context, no matter whether the code is in your…

Op 2010-11-01 11:06, Sven Barth het geskryf:

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.

Thank you very much Sven and Martin. What you said then confirms why my application crashes after X amount of lines were added to the StringGrid, but worked correctly when the event was triggered inside the Synchronize() call.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net:8080/fpgui/

Reply by email