On Thu, Mar 5, 2015 at 6:48 AM, Constantine Yannakopoulos < alfasud...@gmail.com> wrote:
> On Thu, Mar 5, 2015 at 2:11 AM, silvioprog <silviop...@gmail.com> wrote: > >> What do you think about a TDataSetEnumerator class in the DB unit? >> Something like this: >> >> === begin code === >> >> > function TDataSetEnumerator.MoveNext: Boolean; >> begin >> Inc(FPosition); >> if FPosition = FDataSet.RecordCount then >> Exit(False); >> FDataSet.MoveBy(FPosition); >> Result := True; >> end; >> > > 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. > Thanks for the information. So we can change it to (FCL have no a .MoveNext, so I used the .Next method): === begin code === TDataSetEnumerator = class private FDataSet: TDataSet; FFirstDone: Boolean; function GetCurrent: TDataSet; public constructor Create(ADataSet: TDataSet); function MoveNext: Boolean; property Current: TDataSet read GetCurrent; end; ... constructor TDataSetEnumerator.Create(ADataSet: TDataSet); begin inherited Create; FDataSet := ADataSet; FDataSet.First; end; function TDataSetEnumerator.GetCurrent: TDataSet; begin Result := FDataSet; end; function TDataSetEnumerator.MoveNext: Boolean; begin if FFirstDone then FDataSet.Next else FFirstDone := True; Result := not FDataSet.EOF; end; === end code === Thank you! -- Silvio Clécio My public projects - github.com/silvioprog
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal