<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Mar 10, 2015 at 5:48 PM, 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div><div class="h5"><div class="gmail_quote">On Sat, Mar 7, 2015 at 4:27 AM, LacaK <span dir="ltr"><<a href="mailto:lacak@zoznam.sk" target="_blank">lacak@zoznam.sk</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><u></u>What if TDataSetEnumerator.Current will return TFields instead of TDataSet which enumerates?<u></u><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"><u></u> end;<u></u></div></div><div style="font-family:serif;font-size:16px"><u></u><br><u></u></div><div style="font-family:serif;font-size:16px"><u></u>I know that it is more or less same ... it depends what will be most common usage scenario.<u></u></div><div style="font-family:serif;font-size:16px"><u></u>In one case it will be better have DataSet in another Fields.<u></u></div><div style="font-family:serif;font-size:16px"><u></u>When iterating DataSet IMO only Fields, Recno, Bookmark are usable properties which changes on each itteration and can be practically used inside loop.<u></u></div><div style="font-family:serif;font-size:16px"><u></u>But I think, that most common scenario will be use only Fields inside loop.<u></u></div><div><u></u>In both cases user must define "control variable" either of TDataSet type or TFields type.<u></u></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><span><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></span><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"><span><div>constructor TDataSetEnumerator.Create(ADataSet: TDataSet);</div><div>begin</div><div> inherited Create;</div><div> FDataSet := ADataSet;</div></span><div> FBOF := True;</div><div> FDataSet.First;</div><div>end;<u></u><div><br></div><div>function TDataSetEnumerator.GetCurrent: TFields;</div><div>begin</div><div> Result := FDataSet.Fields;</div><span><div>end;</div><div><br></div><div>function TDataSetEnumerator.MoveNext: Boolean;</div><div>begin</div></span><div> if FBOF then</div><div> FBOF := False</div><div> else</div><div> FDataSet.Next;</div><span><div> Result := not FDataSet.EOF;</div><div>end;</div><div><br></div></span><div>(* *** *)</div><div><br></div><div>-Laco.</div></div></font></div></div></blockquote></div><div><br></div></div></div><div>Very nice. I open a new issue about that (<a href="http://bugs.freepascal.org/view.php?id=27644" target="_blank">http://bugs.freepascal.org/view.php?id=27644</a>). =)</div><div><br></div><div>I have a question. Can I use two or more enum operators in a same unit?</div></div></div></blockquote><div><br></div><div>It was applied in trunk. Thanks guys! (y)</div><div> </div></div>-- <br><div class="gmail_signature">Silvio Clécio<br>My public projects - <a href="http://github.com/silvioprog" target="_blank">github.com/silvioprog</a></div>
</div></div>