wwwdrago wrote:
>> call Application.ProcessMessages from time to time within your
>> SomeLongProcess
>
> Yes, would be fine, but unfortunately I cannot modified the code
> inside SomeLongProcess. The time consuming process uses an external
> library.
How does it tell you that it's making progress? If you cannot accurately
indicate the progress made, please do not use a TProgressBar. Instead,
use something cyclical, just something to mean, "The program hasn't
completely hung yet."
Here's what you do. Write a TThread descendant like this:
type
TDragoThread = class(TThread)
protected
procedure Execute; override;
end;
procedure TDragoThread.Execute;
begin
SomeLongProcess;
end;
In your main thread, create an instance of TDragoThread like this:
ProgressIndicator.Enabled := True;
Thread := TDragoThread.Create(True);
Thread.OnTerminate := LongProcessFinished;
Thread.FreeOnTerminate := True;
Thread.Resume;
I assume ProgressIndicator is an instance of TTimer. Now write the
LongProcessFinished procedure:
procedure TDragoForm.LongProcessFinished(Sender: TObject);
begin
ProgressIndicator.Enabled := False;
end;
Now the long process will run in a separate thread. That leaves your
main thread free to do whatever it wants, including handling the timer
messages generated for ProgressIndicator, and updating its display. When
the long process finishes, the LongProcessFinished method will get
executed in the context of your main thread. After that method returns,
the thread object will free itself.
--
Rob