Skip to content

martinusso/datasetiterator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

datasetiterator

This fork has slight differences with the original repository, that's hosted on BitBucket at https://bitbucket.org/magnomp/datasetiterator.

Using

uses
  DataSetIterator;

var
  I: IDataSetIterator;
  Sum: Integer;
begin
  { Ok, using aggregates here would be even better. This is just an example }

  Sum := 0;
  I := Iterator(ClientDataSet1);
  while I.Next do
    Inc(Sum, ClientDataSet1FOOBAR.AsInteger);

Motivation

Why the DataSetIterator exists? The code below is a common way to iterate over the Dataset. DataSetIterator does this in a simple, efficient and safe way.

var
  Bookmark: TBookmark;
  Sum: Integer;
begin
  Sum := 0;
  Bookmark := ClientDataSet1.Bookmark;
  ClientDataSet1.DisableControls;
  try
    ClientDataSet1.First;
    while not ClientDataSet1.Eof do
    begin
      Inc(Sum, ClientDataSet1FOOBAR.AsInteger);
      ClientDataSet1.Next; { Who haven't ever forgot to call Next here... }
    end;
  finally
    ClientDataSet1.Bookmark := Bookmark;
    ClientDataSet1.FreeBookmark(Bookmark);
    ClientDataSet1.EnableControls; { ...or called EnableContraints instead of
                                        EnableControls here? }
  end;

Author

DataSetIterator.pas was originally developed by Magno Machado.

About

A nice way to iterate over the records on a dataset

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages