EOF dont get TRUE

The official tester's forum for ZeosLib 7.1. Ask for help, post proposals or solutions.
Post Reply
carloszocante
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 07.05.2014, 19:00

EOF dont get TRUE

Post 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!
majlumbo
Fresh Boarder
Fresh Boarder
Posts: 10
Joined: 17.01.2010, 03:15

Re: EOF dont get TRUE

Post 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;
carloszocante
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 07.05.2014, 19:00

Re: EOF dont get TRUE

Post 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!
majlumbo
Fresh Boarder
Fresh Boarder
Posts: 10
Joined: 17.01.2010, 03:15

Re: EOF dont get TRUE

Post 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/
carloszocante
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 07.05.2014, 19:00

Re: EOF dont get TRUE

Post by carloszocante »

I checked all the events and there is nothing. And I have already tested with the latest version, and it persists.
Weird.
carloszocante
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 07.05.2014, 19:00

Re: EOF dont get TRUE

Post by carloszocante »

If I try with BOF and Prior it works. :?
carloszocante
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 07.05.2014, 19:00

Re: EOF dont get TRUE

Post 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?
Post Reply