1
I’m trying to raise a progressbar
within my repeating structure, however the progressbar
always locks the application. I will demonstrate here, follows the code:
It would be correct to try to use this way?
ProgressBar1.Position:=0;
While ... do
begin
DModuleGrid.ZQuery3.Close;
DModuleGrid.ZQuery3.SQL.Clear;
DModuleGrid.ZQuery3.SQL.Add('SELECT count(*) FROM cupatres WHERE numcupom = :pcoo2 ');
DModuleGrid.ZQuery3.SQL.Add('AND NSerie = :pecf1 AND ccf = :pccf3 AND Retorno = :pret4 ');
DModuleGrid.ZQuery3.SQL.Add('AND diavenda BETWEEN "'+pdate1treg+'" AND "'+pdate2treg+'"');
DModuleGrid.ZQuery3.ParamByName('pcoo2').AsString := copy(lTemp,47,6);
DModuleGrid.ZQuery3.ParamByName('pccf3').AsString := copy(lTemp,53,6);
DModuleGrid.ZQuery3.ParamByName('pret4').AsString := copy(lTemp,59,3);
DModuleGrid.ZQuery3.ParamByName('pecf1').AsString := copy(lTemp,4,20);
DModuleGrid.ZQuery3.Open;
DModuleGrid.ZQuery3.FetchAll;
rc1 := DModuleGrid.ZQuery3.RecordCount-1;
ProgressBar1.Max := rc1;
ProgressBar1.Position:= ProgressBar1.Position+1;
Sleep(50);
Application.ProcessMessages;
end;
What is the "code here"? Sure it is the progressbar? It works without it?
– Filipe.Fonseca
@Filipe.Fonseca, works smoothly without it (progressbar), the code is huge.
– Ramon Ruan
Does the huge code access bank? You can tell if the system freezes while running the while without having the progressbar there?
– Filipe.Fonseca
Try to add
application.processmessages;
in place of Sleep. If I get a response explaining the pq.– Filipe.Fonseca
@Filipe.Fonseca, the code accesses bank yes, I’m testing with the
application.processmessages;
, if it works I return! Thanks!– Ramon Ruan
@Fonseca, it worked, yes, he passed the code right, however, the progressibar does not process, it stands at 100%.
– Ramon Ruan
I would discourage you from using Sleep unless you have a clear reason for it. It causes the processor to swap threads and does not help in anything to the progress of the method and taking another half second at each step of the loop for the user
– Caputo
@Caputo, what would encourage then friend? Wanted something to make the bar Progress run without crashing ;/
– Ramon Ruan
We are with a big problem here right now. But in the late afternoon put an example of how to do. A question: What is the maxvalue of your bar Progress? how are you calculating it? In your example does not show the maxvalue setting
– Caputo
@Caputo, this is the problem, because when I put the maxvalue of the progressibar, which in this case would be the record of the query, but, does not return me anything, I believe q the amount of records is picking from another corner.
– Ramon Ruan
@DBX8, it’s actually pq. he’s just logging into the database to grab and compare the records I need, he’s not going through the database completely.
– Ramon Ruan