Member_2_5194534
asked on
Showing progress from multiply threads
I opened this new discussion especially for Geert_Gruwez, about his article of:
https://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/A_239-Displaying-progress-in-the-main-form-from-a-thread-in-Delphi.html#discussion
So, lets continue the talk here, as the admin stated we need to open a new topic about this instead of continueing it in the other one.
so, as you saw, i store each thread's personal handle to the TProgressBar in an array of TProgressBar.
how many progress bars are being created at run time ? that's the user choice, using SetLength on the array.
so you said something like:
"your form needs to know what thread is corresponding to what progressbar
what are you using to start the multiple threads ?
at the time you start the threads, i imagine you are creating just as many progressbars ?
ah here :
with TFetchDataThread.Create(
alabel[nLoop], apbar[nLoop], hOpenFile[nLoop], hInetFile[nLoop], i64Start, i64End ) do
begin
Priority := tpNormal;
Start;
end;
you basically pass the progressbar to the thread
but ... it would be better if you pass this variable to the routine in the callback
sample callback :"
https://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/A_239-Displaying-progress-in-the-main-form-from-a-thread-in-Delphi.html#discussion
So, lets continue the talk here, as the admin stated we need to open a new topic about this instead of continueing it in the other one.
so, as you saw, i store each thread's personal handle to the TProgressBar in an array of TProgressBar.
how many progress bars are being created at run time ? that's the user choice, using SetLength on the array.
so you said something like:
"your form needs to know what thread is corresponding to what progressbar
what are you using to start the multiple threads ?
at the time you start the threads, i imagine you are creating just as many progressbars ?
ah here :
with TFetchDataThread.Create(
alabel[nLoop], apbar[nLoop], hOpenFile[nLoop], hInetFile[nLoop], i64Start, i64End ) do
begin
Priority := tpNormal;
Start;
end;
you basically pass the progressbar to the thread
but ... it would be better if you pass this variable to the routine in the callback
sample callback :"
type
TProgressCallback = procedure (Sender: TObject; aProgress: TObject; aProcent: Integer);
and in your form:
procedure TFormxXXX.ThreadProgress(Sender: TObject; aProgress: TObject; aProcent: Integer);
begin
// Assuming min = 0 and Max = 100
TProgressBar(AProgress).Position := aProcent;
TProgressBar(AProgress).Update;
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.