It has been asked before, but without a full answer. This is to do with the so called famous \"‘Fatal threading model!’\".
I need to replace this call to TThread.Su
To elaborate on the original answer, (and on Smasher's rather short explanation), create a TEvent object. This is a synchronization object that's used for threads to wait on the right time to continue.
You can think of the event object as a traffic light that's either red or green. When you create it, it's not signaled. (Red) Make sure that both your thread and the code that your thread is waiting on have a reference to the event. Then instead of saying Self.Suspend;
, say EventObject.WaitFor(TIMEOUT_VALUE_HERE);
.
When the code that it's waiting on is finished running, instead of saying ThreadObject.Resume;
, you write EventObject.SetEvent;
. This turns the signal on (green light) and lets your thread continue.
EDIT: Just noticed an omission above. TEvent.WaitFor is a function, not a procedure. Be sure to check it's return type and react appropriately.