<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Mar 5, 2015 at 6:48 AM, Constantine Yannakopoulos <span dir="ltr"><<a href="mailto:alfasud.ti@gmail.com" target="_blank">alfasud.ti@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span>On Thu, Mar 5, 2015 at 2:11 AM, silvioprog <span dir="ltr"><<a href="mailto:silvioprog@gmail.com" target="_blank">silvioprog@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">What do you think about a TDataSetEnumerator class in the DB unit? Something like this:<div><br></div><div>=== begin code ===</div><div><div> </div></div></div></blockquote></span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>function TDataSetEnumerator.MoveNext: Boolean;<span><div><div>begin</div><div> Inc(FPosition);</div><div> if FPosition = FDataSet.RecordCount then</div><div> Exit(False);</div><div> FDataSet.MoveBy(FPosition);</div><div> Result := True;</div><div>end;</div></div></span></div></div></blockquote><div><br><div style="font-family:'trebuchet ms',sans-serif">I'm not sure for FPC but in Delphi there are datasets that do not fully implement the properties .RecNo and .RecordCount, server cursor datasets for
example always return -1 if memory serves. IMHO the .MoveNext method should be written
in such a way as to not use .RecordCount but only .Eof which is the only property
that is guaranteed to always work correctly in all datasets.<br></div></div></div></div></div></blockquote></div><div><br></div><div>Thanks for the information.</div><div><br></div><div>So we can change it to (FCL have no a .MoveNext, so I used the .Next method):</div><div><br></div><div>=== begin code ===</div><div><br></div><div><div> TDataSetEnumerator = class</div><div> private</div><div> FDataSet: TDataSet;</div><div> FFirstDone: Boolean;</div><div> function GetCurrent: TDataSet;</div><div> public</div><div> constructor Create(ADataSet: TDataSet);</div><div> function MoveNext: Boolean;</div><div> property Current: TDataSet read GetCurrent;</div><div> end;</div></div><div><br></div><div>...</div><div><br></div><div><div>constructor TDataSetEnumerator.Create(ADataSet: TDataSet);</div><div>begin</div><div> inherited Create;</div><div> FDataSet := ADataSet;</div><div> FDataSet.First;</div><div>end;</div><div><br></div><div>function TDataSetEnumerator.GetCurrent: TDataSet;</div><div>begin</div><div> Result := FDataSet;</div><div>end;</div><div><br></div><div><div>function TDataSetEnumerator.MoveNext: Boolean;</div><div>begin</div><div> if FFirstDone then</div><div> FDataSet.Next</div><div> else</div><div> FFirstDone := True;</div><div> Result := not FDataSet.EOF;</div><div>end;</div></div></div><div><br></div><div>=== end code ===</div><div><br></div><div>Thank you!</div><div><br></div>-- <br><div>Silvio Clécio<br>My public projects - <a href="http://github.com/silvioprog" target="_blank">github.com/silvioprog</a></div>
</div></div>