The graphical user interface must be updated by the main thread. You have to put your search code in a separate thread, and while the crawler thread is running, your main thread may show the animation along with a βWaitβ message.
Your search stream can notify the main stream when a search is performed using any of the available synchronization technologies. The easiest way is to define a method in your stream class that stops the animation in the user interface, and pass this method Synchronize at the end of the Execute method of your search stream.
The code for your search stream will look something like this:
type TMyThread = class(TThread) private procedure NotifyEndOfThread; protected procedure Execute; override; end; implementation uses MainFormUnit; procedure TMyThread.NotifyEndOfThread; begin MainForm.ShowAnimation := False; end; procedure TMyThread.Execute; begin try {Add your search code here} finally Synchronize(NotifyEndOfThread); end; end;
And your main stream code will be like this:
TMainForm = class(TForm) ... private FShowAnimation : Boolean; procedure SetShowAnimation(Value: Boolean); public property ShowAnimation : Boolean read FShowAnimation write SetShowAnimation; end; procedure TMainForm.SetShowAnimation(Value: Boolean); begin FShowAnimation := Value; if FShowAnimation then {Add animation code here} else {Stop animation} end;
source share