|Subject:||Re: Multiple Files download and progress update|
|Posted by:||Remy Lebeau (Indy Team) (email@example.com)|
|Date:||Mon, 2 Oct 2006|
"Clément Doss" <firstname.lastname@example.org> wrote in message
> I am still doing my FTpClient improvments. As I have written the
> FTP thread, I would like to show some progress (progress bar).
> What would be the correct to implement this?
The best way is to have the thread post custom status messages to the main
thread. The main thread can then decide how to display the status to the
> Create the form on the Thread.Execute method
Never create a VCL TForm in the context of a worker thread. The UI controls
of the VCL are not thread-safe.
> hook the OnWork, OnWorkBegin and OnWorkEnd
Yes. For example, in my code, I have the event handlers post a custom
window message to the main thread, and the main thread then displays all
active downloads in a ListView with progress bars drawn inside the
individual list items.
> In that case, do I need to call synchronize
If you want the thread to access the UI directly, then yes.
> I mean, the thread /has/ its own form
It should not have that. Have a form contain a thread internally. Not the
other way around.
> so there should be 2 threads accessing the same form at any time?
That is the issue to avoid at all costs. The main thread should be the only
thread to access anything UI-related.
> A form that will create the thread and hook itself to the thread.
That is a better way to go.
> And once again, do I need to call synchronize for the progress bar update?
Yes. Unless you use custom messages.
Multiple Files download and progress update posted by Clément_Doss on Mon, 02 Oct 2006