In my Delphi client application, I need a way to show a progress bar while tables are opened.
When the Delphi client and the custom Delphi DAServer are both on the same LAN the latency is tolerable, but if my client is accessing the server from the internet, the client seems freezing while opening the tables.
Can someone please show me where should I put some code to animate a kind of progress bar?
Thank you
You could handle onReadDatasetProgess event of appropriate TDADataStreamer descedant that is used for reading/writing data in your application. This event fires after reading of every row of the dataset.
I think that I need to handle onReadDatasetProgess within a thread, since using from the main thread nothing is updated on the main form where I’ve a progressBar.
CAn someone please show how can I accomplish this?
thank you
Do you call ProgressBar.StepIt method from the onReadDatasetProgress event? The following code is working for me, progress bar is updated o the main form:
procedure TClientDataModule.DataStreamerReadDatasetProgress(
Sender: TDADataStreamer; const aDataset: IDADataset; const aCurrent,
aTotal: Integer);
begin
ClientForm.ProgressBar1.Max:=aTotal;
ClientForm.ProgressBar1.StepIt;
end;
If you do the same and nevertheless have problems, please, send us a testcase.
Best regards
Your solution works quite well, but as a matter of a mere exercise to learn something new, I ended up writing a little snippet of code implementing a queue thread…
Instead of updating progress on the main form (which in fact is created after the data module form, I instantiated a dedicated form with a progress bar on it. fWaitForm is created in ClientDataModule.OnCreate:
procedure TClientDataModule.DataStreamerReadDatasetProgress(Sender:
TDADataStreamer; const aDataset: IDADataset; const aCurrent, aTotal:
Integer);
begin
if Assigned(fWaitForm) then
begin
Sleep(100);
fWaitForm.Show;
TThread.Queue(nil,
procedure begin
fWaitForm.ProgressBar.Max := aTotal;
fWaitForm.ProgressBar.StepIt;
fWaitForm.ProgressBar.Update;
if (aCurrent = aTotal) then
fWaitForm.Hide;
end);
end;
end;