Page 1 of 1

EOF dont get TRUE

Posted: 07.05.2014, 19:10
by carloszocante
hello!

I have been having a problem when I use Eof property:

Code: Select all

ZQuery.First;
ZQuery.DisableControls;
while (not ZQuery.Eof) do 
begin
  (...)
  ZQuery.Edit;
  ZQuery.FieldByName('Total').Value := Total;
  ZQuery.FieldByName('TotalG').Value := TotalG;
  ZQuery.Post;
  ZQuery.ApplyUpdates;
  Application.ProcessMessages;
  ZQuery.Next;
end;
ZQuery.EnableControls;
The problem is that EOF does not change to True, that's why I get a infinity loop.
I tried removing the DisableControls but the problem persists.
Any ideas?

PS: Sorry for my bad English!

Re: EOF dont get TRUE

Posted: 08.05.2014, 17:02
by majlumbo
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;

Re: EOF dont get TRUE

Posted: 09.05.2014, 16:17
by carloszocante
Hello majlumbo, thanks for your reply!

1º - I call the EnableControls at the end of the code, just scroll down the bar and you will see it.
2º - Good point, I will disable the button.
3º - I tested it with the CachedUpdates = False but the problem persists.
4º - It only works if I remove both DisableControls and EnableControls. But without them the process becomes very slow!

What annoys me is that this code works at Delphi 7 + Zeos 6.6.6. This problem occours at Delphi XE3 + Zeos 7.1.2-stable.

Again, sorry about my English!

Re: EOF dont get TRUE

Posted: 09.05.2014, 18:44
by majlumbo
Sorry, I did miss the EnableControls...

Do you have anything attached to this query's Before/AfterEdit, or Before/AfterPost? That may be interrupting the process flow of the loop. If So, you may want to disable them and re-enable at the end.

Code: Select all

ZQuery.AfterPost := nil;
try
   ...
finally
   ZQuery.AfterPost := ZQueryAfterPost;
end;
Also, you may want to upgrade to the latest version 7.1.3a http://sourceforge.net/projects/zeoslib ... 3a-stable/

Re: EOF dont get TRUE

Posted: 09.05.2014, 19:12
by carloszocante
I checked all the events and there is nothing. And I have already tested with the latest version, and it persists.
Weird.

Re: EOF dont get TRUE

Posted: 09.05.2014, 19:29
by carloszocante
If I try with BOF and Prior it works. :?

Re: EOF dont get TRUE

Posted: 13.05.2014, 14:25
by carloszocante
It just works if I set the DBGrid's DataSource to NIL or if I remove the DisableControls. But this is not right, there is something wrong. Somebody?