Infinite Loop with "While not Cds.Eof"

3

I have while not Eof normal in ClientDataSet . The only detail is in AfterScroll , where I edit the dataset and give it a post in it. When Eof is True , after post it changes to False > . Debugging the situation, I realized internally that the ClientDataSet calls the Resync routine, which in turn calls the ActivateBuffers routine, change the FEOF control to False control. At this point, I remain in the last record of my ClientDataSet , however he understands that he is not in Eof .

How can I resolve this? Is a bug of 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 EOF is set, after Post, EOF returns False.

    
asked by anonymous 21.03.2017 / 15:02

1 answer

3

With the help of Reginaldo's comments, I came up with a solution. In , before running Edit / Post, I do an if , checking if the dataset is not as EOF .

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

In this way, it will only execute Edit / Post while there is a record being viewed in the DataSet.

    
21.03.2017 / 18:30