<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    Yeap! That is actually what I posted here (<a
      href="https://gitlab.com/freepascal.org/fpc/source/-/issues/40578">Feature
      Request)</a>.<br>
    <br>
    <blockquote type="cite"
      cite="mid:23445897-218f-4750-8819-3f12cc453b6c@googlemail.com"> You
      simply need to inherit from the list class so that you can make
      the function public. And with a little trick you can also use it
      inside a for-in-loop:<br>
      <br>
      === code begin ===<br>
      <br>
      program tlistitr;<br>
      <br>
      {$mode objfpc}{$H+}<br>
      {$modeswitch advancedrecords}<br>
      <br>
      uses<br>
        Generics.Collections;<br>
      <br>
      type<br>
        TRec = record<br>
          a, b, c: Int64;<br>
          constructor Create(aArg1, aArg2, aArg3: Int64);<br>
        end;<br>
      <br>
        { this way the GetPtrEnumerator function is available; you could
      also use a class helper }<br>
        TMyList = class(specialize TList<TRec>)<br>
        public<br>
          function GetPtrEnumerator: specialize TEnumerator<PT>;<br>
        end;<br>
      <br>
      constructor TRec.Create(aArg1, aArg2, aArg3: Int64);<br>
      begin<br>
        a := aArg1;<br>
        b := aArg2;<br>
        c := aArg3;<br>
      end;<br>
      <br>
      function TMyList.GetPtrEnumerator: specialize
      TEnumerator<PT>;<br>
      begin<br>
        Result := inherited GetPtrEnumerator();<br>
      end;<br>
      <br>
      { with this you can simply do "for PtrTypeVar in
      List.GetPtrEnumerator do",<br>
        though this *might* not work in mode Delphi... }<br>
      operator Enumerator(aEnum: specialize
      TEnumerator<TMyList.PT>): specialize
      TEnumerator<TMyList.PT>;<br>
      begin<br>
        Result := aEnum;<br>
      end;<br>
      <br>
      var<br>
        l: TMyList;<br>
        r: TRec;<br>
        p: TMyList.PT;<br>
      begin<br>
        l := TMyList.Create;<br>
        l.Add(TRec.Create(1, 2, 3));<br>
        l.Add(TRec.Create(9, 8, 7));<br>
        for p in l.GetPtrEnumerator do begin<br>
          Writeln(p^.a, ' ', p^.b, ' ', p^.c);<br>
        end;<br>
      end.<br>
      <br>
      === code end ===<br>
      <br>
      Regards,<br>
      Sven<br>
      <br>
      <fieldset class="moz-mime-attachment-header"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
fpc-pascal maillist  -  <a class="moz-txt-link-abbreviated" href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>