Infinite loop with "While not Cds.Eof’s"

Asked

Viewed 1,107 times

3

I have a while not Eof normal in a Clientdataset.
The only detail is in Afterscroll, where I edit the dataset in question and I give a post in the same. When the Eof is True, after the post he changes to False. Debugging the situation, I realized that internally the Clientdataset calls the routine Resync, which in turn, calls the routine Activatebuffers, and this finally changes the control FEOF for False. At this point, I continue on the last record of my Clientdataset, but he understands that he is not in Eof.

How can I fix it? It’s a bug delphi?

Code:

Cds.First;  
While not Cds.Eof do  
begin  
  Sleep(10);//Exemplo  
  Cds.Next;  
end;  

Afterscroll

Cds.Edit;  
Cds.FieldByName('QTDE').AsFloat := 10;  
Cds.Post;

In Afterscroll, when it is EOF, after the Post the EOF returns to False.

  • 1

    If it is positioned on the last record then it is not EOF.

  • @Reginaldorigo You’re right, I expressed myself wrong (sorry). But after the Cds.Next, gets into the Afterscroll and at that moment it is already as EOF, the problem is that after the post on the CDS, the EOF is amended to False.

  • Andrey, put your code :)

  • From what you have said, it repositions the pointer on the last record and this confuses the logic you used in your flow. I think you need to change this flow or this logic.

  • Guys, I found out with the help of @Reginaldorigo. It really was logic problem. Because it was already EOF, there was no record selected, when it was given Edit/Post, it returned to the last valid record, but the EOF actually stopped being True. Thank you.

1 answer

3


With the help of Reginaldo’s comments, I’ve come up with a solution.
In the Afterscroll, before executing the Edit / Post, make a if, checking whether the dataset is not as EOF.

if not Cds.Eof then
begin
  Cds.Edit;  
  Cds.FieldByName('QTDE').AsFloat := 10;  
  Cds.Post;
end;

This way, it will only run Edit / Post while there is a record being viewed in Dataset.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.