Hi,
Using TJvGradientProgressBar from latest JVCL as progress bars.
I have two progress bars within a loop that scrolls through all the records of a UniQuery.
pbCurrentOp2 and pbOverall are not updating despite having Application.ProcessMessage (3 of them!!) inside the loop.
Code and screenshot follows:
Code: Select all
procedure TfMain.btnStartClick(Sender: TObject);
var
bakFl, imgFld, imgFl: string;
p, r, t: integer;
begin
(*
Steps:
- Create embedded MySQL database
- 0.Connect to database
- 1.Import from MySQL Backup script file into this database - 33% overall
- 2.Extract images to folder - 33% overall
- 3.Transfer data to Firebird - 33% overall
*)
//EnableUniSQL := False;
try
//UniConnection1.SpecificOptions.Values['EmbeddedParams'] := '--basedir=.'#13#10'--datadir=.\data';
//Operation stage 1
UniConnection1.ExecSQL('DROP DATABASE IF EXISTS mydb;', []);
UniConnection1.ExecSQL('CREATE DATABASE mydb;', []);
pbCurrentOp1.Position := 10;
pbOverall.Position := 10;
lblOvlPrg.Caption := Format('%d %%', [10]);
Application.ProcessMessages;
UniConnection1.Database := 'mydb';
UniConnection1.Open;
bakFl := deBackupFl.Text;
UniDump1.RestoreFromFile(bakFl);
//Operation stage 2
UniQuery2.Open;
t := UniQuery2.Fields[0].AsInteger;
UniQuery2.Close;
imgFld := deImgFolder.Text;
if imgFld[Length(imgFld)] '\ then
imgFld := imgFld + '\;
with UniQuery1 do
begin
DisableControls;
Open;
First;
r := 0;
while not EOF do
begin
Inc(r);
if FieldByName('individual_id').IsNull then
begin
Next;
Continue;
end;
imgFl := imgFld + FieldByName('individual_id').AsString + '.jpg';
TBlobField(FieldByName('Scan')).SaveToFile(imgFl);
p := r div t * 100;
pbCurrentOp2.Position := p;
lblCurOpPrg2.Caption := Format('%d %%', [p]);
pbOverall.Position := 33 + Trunc(p * 0.33);
lblOvlPrg.Caption := Format('%d %%', [33 + Trunc(p * 0.33)]);
Application.ProcessMessages;
Application.ProcessMessages;
Application.ProcessMessages;
Next;
end;
Close;
end;
//Operation stage 3
UniConnection1.Close;
Caption := Caption + ' - Complete!';
except
on E: Exception do
ShowMessage('Error: ' + E.Message);
end;
end;
procedure TfMain.deBackupFlBeforeDialog(Sender: TObject; var AName: string;
var AAction: boolean);
begin
AAction := False;
if OpenDialog1.Execute then
begin
deBackupFl.Text := OpenDialog1.FileName;
end;
end;
procedure TfMain.UniDump1RestoreProgress(Sender: TObject; Percent: integer);
begin
pbCurrentOp1.Position := Percent;
lblCurOpPrg1.Caption := Format('%d %%', [Percent]);
pbOverall.Position := 10 + Trunc(Percent * 0.23);
lblOvlPrg.Caption := Format('%d %%', [10 + Trunc(Percent * 0.23)]);
Application.ProcessMessages;
end;

Please note that the pbCurrentOp1 progress bar (in UniDump1RestoreProgress method) updates on screen correctly. It is only the ones in the loop that are not updating on screen as the loop progresses. Rather the progress bars are updated on screen only after the loop completes.
Am I doing anything wrong? Is there any technique to have the progressbars to update while loop is executing?
TIA.
Regards,
Steve Faleiro