<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div>Hi,<br><br></div>This article is quite clear for me: <a href="http://wiki.freepascal.org/for-in_loop">http://wiki.freepascal.org/for-in_loop</a><br>
<br></div>But let say that I have this class:<br><br></div>TMyList = class<br></div>private<br></div> FList: TList<br></div>public<br></div> constructor Create;<br></div> destructor Destroy;<br><br></div><div> procedure Add;<br>
</div><div> procedure Remove;<br></div>end;<br><br></div>Now I want to do:<br><br></div>for a in MyClass do<br></div>begin<br><br></div>end;<br><br></div>Can I do this without creating new enumerator? I mean pass enumerator from FList? I'm confused because if I create function:<br>
<br></div>function TMyClass.GetEnumerator: TListEnumerator<br></div>begin<br></div> Result := FList.GetEnumerator;<div>end;<br><div><div><div><div><div><div><div><br></div><div>... then FList.GetEnumerator create new object (TListEnumerator.Create(Self)). My question is, where it is freed? Is it freed automatically on runtime after exit from loop? I don't want memory leak<br>
<br>Regards<br></div></div></div></div></div></div></div></div></div>