What if TDataSetEnumerator.Current will return TFields instead of TDataSet which enumerates?

Example:
  procedure IterateDataSet;
  var DataSet, DS: TDataSet;
      Flds: TFields;
      F: TField;
  begin
    for Flds in DataSet do
      for F in Flds do  // DataSet can be still accessed by Flds.DataSet
        writeln(F.AsString,'|');  
  end;

I know that it is more or less same ... it depends what will be most common usage scenario.
In one case it will be better have DataSet in another Fields.
When iterating DataSet IMO only Fields, Recno, Bookmark are usable properties which changes on each itteration and can be practically used inside loop.
But I think, that most common scenario will be use only Fields inside loop.
In both cases user must define "control variable" either of TDataSet type or TFields type.

(*** Example implementation ***)
type
  TDataSetEnumerator = class
    private
      FDataSet: TDataSet;
      FBOF: Boolean;
      function GetCurrent: TFields;
    public
    &nb sp; constructor Create(ADataSet: TDataSet);
      function MoveNext: Boolean;
      property Current: TFields read GetCurrent;
  end; 

operator Enumerator(ADataSet: TDataSet): TDataSetEnumerator;
begin
  Result := TDataSetEnumerator.Create(ADataSet);
end; 

constructor TDataSetEnumerator.Create(ADataSet: TDataSet);
begin
  inherited Create;
  FDataSet := ADataSet;
  FBOF := True;
  FDataSet.First;
end;

function TDataSetEnumerator.GetCurrent: TFields;
begin
  Result := FDataSet.Fields;
end;

function TDataSetEnumerator.MoveNext: Boolean;
begin
  if FBOF then
    FBOF := False
  else
    FDataSet.Next;
  Result := not FDataSet.EOF;
end;

(* *** *)

-Laco.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to