You can use a TEvent from the SyncObjs unit.
TMyThread = class(TThread)
public
SignalEvent : TEvent;
procedure Execute; override;
end;
TMyForm = class(TForm)
procedure Button1Click(Sender : TObject);
public
myThread : TMyThread;
end;
The thread does its work, then waits for the event to be signalled by the button click event. By using a TEvent you can also specify a timeout. (or 0 to wait indefinitely).
procedure TMyForm.Button1Click(Sender : TObject);
begin
// Tell the thread that the button was clicked.
myThread.SignalEvent.SetEvent;
end;
procedure TMyThread.Execute;
var
waitResult : TWaitResult;
begin
// do stuff
// Wait for the event to signal that the button was clicked.
waitResult := SignalEvent.WaitFor(aTimeout);
if waitResult = wrSignaled then
begin
// Reset the event so we can use it again
SignalEvent.ResetEvent;
// do some more stuff
end else
// Handle timeout or error.
end;