You call DisableControls, but I don't see you calling EnableControls.
You also call Application.ProcessMessages in your loop. I understand why you are doing so, but that may cause side-effects. You may want to disable the control used to enter this procedure (such as BitBtn?) as you enter, and re-enable it just before leaving to ensure the user doesn't re-enter this loop in the middle by pressing the button again.
Also, if you are going to ApplyUpdates after each iteration, then rather than call ApplyUpdates, just simply set ZQuery.CachedUpdates := False; before you enter the while and set it back to True after you exit the while. This will persist the changes automatically.
Code: Select all
BitBtnX.Enabled := False;//disable the control used to enter this routine
try
ZQuery.DisableControls;
try
ZQuery.CachedUpdates := False;
ZQuery.First;
while (not ZQuery.Eof) do
begin
(...)
ZQuery.Edit;
ZQuery.FieldByName('Total').Value := Total;
ZQuery.FieldByName('TotalG').Value := TotalG;
ZQuery.Post;
Application.ProcessMessages;
ZQuery.Next;
end;
ZQuery.CachedUpdates := True;
finally
ZQuery.EnableControls;
end;
finally
BitBtnX.Enabled := True;
end;