Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Delphi For in loop support requires on of the following: (<a href="http://docwiki.embarcadero.com/RADStudio/en/E2430_for-in_statement_cannot_operate_on_collection_type_&#39;%25s&#39;_(Delphi)" rel="nofollow noreferrer">From the Docs</a>)</p> <ul> <li>Primitive types that the compiler recognizes, such as arrays, sets or strings </li> <li>Types that implement IEnumerable </li> <li>Types that implement the GetEnumerator pattern as documented in the Delphi Language Guide</li> </ul> <p>If you look at Generics.Collections.pas you will find the implementation for <code>TDictionary&lt;TKey,TValue&gt;</code> where it has three enumerators for <code>TKey</code>, <code>TValue</code>, and <code>TPair&lt;TKey,TValue&gt;</code> types. Embarcadero shows that they have used verbose implementation.</p> <p>You could do something like this:</p> <pre><code>unit Generics.AnonEnum; interface uses SysUtils, Generics.Defaults, Generics.Collections; type TAnonEnumerator&lt;T&gt; = class(TEnumerator&lt;T&gt;) protected FGetCurrent : TFunc&lt;TAnonEnumerator&lt;T&gt;,T&gt;; FMoveNext : TFunc&lt;TAnonEnumerator&lt;T&gt;,Boolean&gt;; function DoGetCurrent: T; override; function DoMoveNext: Boolean; override; public Constructor Create(aGetCurrent : TFunc&lt;TAnonEnumerator&lt;T&gt;,T&gt;; aMoveNext : TFunc&lt;TAnonEnumerator&lt;T&gt;,Boolean&gt;); end; TAnonEnumerable&lt;T&gt; = class(TEnumerable&lt;T&gt;) protected FGetCurrent : TFunc&lt;TAnonEnumerator&lt;T&gt;,T&gt;; FMoveNext : TFunc&lt;TAnonEnumerator&lt;T&gt;,Boolean&gt;; function DoGetEnumerator: TEnumerator&lt;T&gt;; override; public Constructor Create(aGetCurrent : TFunc&lt;TAnonEnumerator&lt;T&gt;,T&gt;; aMoveNext : TFunc&lt;TAnonEnumerator&lt;T&gt;,Boolean&gt;); end; implementation { TEnumerable&lt;T&gt; } constructor TAnonEnumerable&lt;T&gt;.Create(aGetCurrent: TFunc&lt;TAnonEnumerator&lt;T&gt;, T&gt;; aMoveNext: TFunc&lt;TAnonEnumerator&lt;T&gt;, Boolean&gt;); begin FGetCurrent := aGetCurrent; FMoveNext := aMoveNext; end; function TAnonEnumerable&lt;T&gt;.DoGetEnumerator: TEnumerator&lt;T&gt;; begin result := TAnonEnumerator&lt;T&gt;.Create(FGetCurrent,FMoveNext); end; { TAnonEnumerator&lt;T&gt; } constructor TAnonEnumerator&lt;T&gt;.Create(aGetCurrent: TFunc&lt;TAnonEnumerator&lt;T&gt;, T&gt;; aMoveNext: TFunc&lt;TAnonEnumerator&lt;T&gt;, Boolean&gt;); begin FGetCurrent := aGetCurrent; FMoveNext := aMoveNext; end; function TAnonEnumerator&lt;T&gt;.DoGetCurrent: T; begin result := FGetCurrent(self); end; function TAnonEnumerator&lt;T&gt;.DoMoveNext: Boolean; begin result := FMoveNext(Self); end; end. </code></pre> <p>This would allow you declare your Current and MoveNext methods anonymously.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload