Hi,
How to get the current TThread instance?
For example: I created a TThread and called a function, which calls a function .... One of those sub functions needs to call TThread.Synchronize, which needs as parameter the current TThread.
Mattias

Mailing lists / fpc-pascal / 2010-12
6 messages · 4 people ·
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hi,
How to get the current TThread instance?
For example: I created a TThread and called a function, which calls a function .... One of those sub functions needs to call TThread.Synchronize, which needs as parameter the current TThread.
Mattias
Mattias Gaertner wroteHi, How to get the current TThread instance?
There is no documented method.
For example: I created a TThread and called a function, which calls a function .... One of those sub functions needs to call TThread.Synchronize, which needs as parameter the current TThread.
Pass on the TThread instance.
You could use GetCurrentThreadID and a lookup list.
Michael.
Strange.
Am I really the first needing this?
You mean as parameter?
Some functions are predefined events. That means I call them and they call me back. I would like to avoid adding everywhere another parameter.
You could use GetCurrentThreadID and a lookup list.
What about using a
threadvar CurrentThread: Thread;?
TThread could set this in the constructor.
BTW, you can call Synchronize for another thread than the current. Is that allowed?
Mattias
Apparently.
I never needed such a method, and I use threads extensively :-)
Yes.
Some functions are predefined events. That means I call them and they call me back. I would like to avoid adding everywhere another parameter.
I understand that. Well, you could create an event object for the event handler.
This could be done, but will give errors for externally created threads.
But you can easily do this for your own thread objects.
BTW, you can call Synchronize for another thread than the current. Is that allowed?
It's a method like any other. Why not ?
Michael.
And for threads created with BeginThread.
But you can easily do this for your own thread objects.
I also think that's the best solution. If that's not enough, then doing it in tthread won't be enough either (unless you only support applications that exclusively use tthread-based threads).
Jonas
On Tue, 21 Dec 2010 14:29:36 +0100 (CET) Strange. Am I really the first needing this? You…
We currently use this method for our "in Application" scheduler, but IIRC you have to fetch/set the ID in the Execute method. But having the overhead of using threadvars (mentionent on the list some time ago) I am currently looking for another method too.
helmut