<html><body><michael@freepascal.org style="font-family: serif; font-size: 16px;">What if TDataSetEnumerator.Current will return TFields instead of TDataSet which enumerates?</michael@freepascal.org><div style="font-family: serif; font-size: 16px;"><br></div><div style="font-family: serif; font-size: 16px;">Example:</div><div><div><font face="serif"> procedure IterateDataSet;</font></div><div><font face="serif"> var DataSet, DS: TDataSet;</font></div><div><font face="serif"> Flds: TFields;</font></div><div><font face="serif"> F: TField;</font></div><div><font face="serif"> begin</font></div><div><font face="serif"> for Flds in DataSet do</font></div><div><font face="serif"> for F in Flds do // DataSet can be still accessed by Flds.DataSet</font></div><div><font face="serif"> writeln(F.AsString,'|'); </font></div><div style="font-family: serif; font-size: 16
px;"><michael@freepascal.org> end;</michael@freepascal.org></div></div><div style="font-family: serif; font-size: 16px;"><michael@freepascal.org><br></michael@freepascal.org></div><div style="font-family: serif; font-size: 16px;"><michael@freepascal.org>I know that it is more or less same ... it depends what will be most common usage scenario.</michael@freepascal.org></div><div style="font-family: serif; font-size: 16px;"><michael@freepascal.org>In one case it will be better have DataSet in another Fields.</michael@freepascal.org></div><div style="font-family: serif; font-size: 16px;"><michael@freepascal.org>When iterating DataSet IMO only Fields, Recno, Bookmark are usable properties which changes on each itteration and can be practically used inside loop.</michael@freepascal.org></div><div style="font-family: serif; font-size: 16px;"><michael@freepascal.org>But I think, that most common scenario will be use only Fields inside loop.</michael@freepascal.org></div><div style="f
ont-family: serif; font-size: 16px;"><michael@freepascal.org>In both cases user must define "control variable" either of TDataSet type or TFields type.</michael@freepascal.org></div><div style="font-family: serif; font-size: 16px;"><br></div><div style="font-family: serif; font-size: 16px;">(*** Example implementation ***)</div><div style="font-family: serif; font-size: 16px;">type</div><div><div style="font-family: serif; font-size: 16px;"> TDataSetEnumerator = class</div><div style="font-family: serif; font-size: 16px;"> private</div><div style="font-family: serif; font-size: 16px;"> FDataSet: TDataSet;</div><div style="font-family: serif; font-size: 16px;"> FBOF: Boolean;</div><div style="font-family: serif; font-size: 16px;"> function GetCurrent: TFields;</div><div style="font-family: serif; font-size: 16px;"> public</div><div style="font-family: serif; font-size: 16px;"> &nb
sp; constructor Create(ADataSet: TDataSet);</div><div style="font-family: serif; font-size: 16px;"> function MoveNext: Boolean;</div><div style="font-family: serif; font-size: 16px;"> property Current: TFields read GetCurrent;</div><div style="font-family: serif; font-size: 16px;"> end; </div><div style="font-family: serif; font-size: 16px;"><br></div><div><div><font face="serif">operator Enumerator(ADataSet: TDataSet): TDataSetEnumerator;</font></div><div><font face="serif">begin</font></div><div><font face="serif"> Result := TDataSetEnumerator.Create(ADataSet);</font></div><div><font face="serif">end; </font></div></div></div><div><font face="serif"><br></font></div><div><font face="serif"><div>constructor TDataSetEnumerator.Create(ADataSet: TDataSet);</div><div>begin</div><div> inherited Create;</div><div> FDataSet := ADataSet;</div><div> FBOF := True;</div><div> FDataSet.First;</div><div>end;</
div><div><br></div><div>function TDataSetEnumerator.GetCurrent: TFields;</div><div>begin</div><div> Result := FDataSet.Fields;</div><div>end;</div><div><br></div><div>function TDataSetEnumerator.MoveNext: Boolean;</div><div>begin</div><div> if FBOF then</div><div> FBOF := False</div><div> else</div><div> FDataSet.Next;</div><div> Result := not FDataSet.EOF;</div><div>end;</div><div><br></div><div>(* *** *)</div><div><br></div><div>-Laco.</div></font></div></body></html>