Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6044235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:59:19+00:00 2026-05-23T06:59:19+00:00

How can I expose this TList from an interface, as either IEnumerator or IEnumerator<IFungibleTroll>

  • 0

How can I expose this TList from an interface, as either IEnumerator or IEnumerator<IFungibleTroll>? I am using Delphi XE.

Here’s how far I got:

unit FungibleTrollUnit;

interface

uses
  Windows, Messages, SysUtils,
  Variants, Classes, Graphics,
  Controls, Forms,
  Generics.Collections;

type
  IFungibleTroll = interface
    ['{03536137-E3F7-4F9B-B1F5-2C8010A4D019}']
       function GetTrollName:String;
       function GetTrollRetailPrice:Double;
  end;


  TFungibleTrolls = class (TInterfacedObject,IEnumerable<IFungibleTroll>)
      protected
         FTrolls:TList<IFungibleTroll>;

      public
          // IEnumerable
          function GetEnumerator:IEnumerator<IFungibleTroll>;//
//          function GetEnumerator:IEnumerator; overload;

         // find/search app feature requires searching.
         // this

         function FindSingleItemByName(aName:String;patternMatch:Boolean):IFungibleTroll;
         function FindMultipleItemsByName(aName:String;patternMatch:Boolean):IEnumerable<IFungibleTroll>;
         function FindSingleItemByIdentifier(anIdentifer:String):IFungibleTroll;// use internal non-visible identifier to find an app.

         constructor Create;

         property Trolls:TList<IFungibleTroll> read FTrolls; // implements IEnumerable<IFungibleTroll>;??
  private
  end;




implementation


{ TFungibleTrolls }

constructor TFungibleTrolls.Create;
begin
         FTrolls := TList<IFungibleTroll>.Create;

end;

function TFungibleTrolls.FindMultipleItemsByName(aName: String;
  patternMatch: Boolean): IEnumerable<IFungibleTroll>;
begin

end;

function TFungibleTrolls.FindSingleItemByIdentifier(
  anIdentifer: String): IFungibleTroll;
begin

end;

function TFungibleTrolls.FindSingleItemByName(aName: String;
  patternMatch: Boolean): IFungibleTroll;
begin

end;



function TFungibleTrolls.GetEnumerator: IEnumerator<IFungibleTroll>;
begin
  result := FTrolls.GetEnumerator;
end;

//function TFungibleTrolls.GetEnumerator: IEnumerator;
//begin
//  result := FTrolls.GetEnumerator; // type IEnumerator<IFungibleTroll> or IEnumerator?
//end;


end.

I get stuck in one of three errors that I can’t figure out how to solve:

[DCC Error] FungibleTrollUnit.pas(26): E2252 Method 'GetEnumerator' with identical parameters already exists
-or-

[DCC Error] FungibleTrollUnit.pas(19): E2291 Missing implementation of interface method IEnumerable.GetEnumerator
-or-
[DCC Error] FungibleTrollUnit.pas(19): E2291 Missing implementation of interface method IEnumerable.GetEnumerator

It seems I must declare two forms of GetEnumerator, if I declare TFungibleTrolls to implement IEnumerable, but I can’t seem to figure out how to do it, either with overloads, or without overloads, or using a “method resolution clause”, like this:

      function IEnumerable.GetEnumerator = GetPlainEnumerator; // method resolution clause needed?
      function GetEnumerator:IEnumerator<IFungibleTroll>;
      function GetPlainEnumerator:IEnumerator;

This probably seems like a pretty basic use of IEnumerable, and making an Interface support iteration, and yet, I’m stuck.

Update: It seems when I try to do this without first declaring a List<T>, I am falling into a crack caused by the fact that IEnumerable<T> inherits from IEnumerable, and yet, instead of a single get enumerator method, my class must provide multiple ones, and because my class is not a generic, it can’t “map itself” to IEnumerable’s requirements directly unless I use a generic List<T> declaration. Marjan’s sample works, when compiled into a project (.dproj+.dpr) but not when built into a package (.dproj+.dpk) and compiled in the IDE. It works fine from the command line, in a package, but not in the IDE, in a package.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:59:19+00:00Added an answer on May 23, 2026 at 6:59 am

    Not an answer to your question directly (still working on that), but this is what I did to get an “interfaced enumerator”, ie and interfaced class that supports iteration:

    IList<T> = interface(IInterface)
      [...]
      function GetEnumerator: TList<T>.TEnumerator;
      function Add(const Value: T): Integer;
    end;
    
    type
      TBjmInterfacedList<T> = class(TBjmInterfacedObject, IList<T>)
      strict private
        FList: TList<T>;
        function GetEnumerator: TList<T>.TEnumerator;
      strict protected
        function Add(const Value: T): Integer;
      public
        constructor Create; override;
        destructor Destroy; override;
      end;
    
    implementation
    
    constructor TBjmInterfacedList<T>.Create;
    begin
      inherited;
      FList := TList<T>.Create;
    end;
    
    destructor TBjmInterfacedList<T>.Destroy;
    begin
      FreeAndNil(FList);
      inherited;
    end;
    
    function TBjmInterfacedList<T>.GetEnumerator: TList<T>.TEnumerator;
    begin
      Result := FList.GetEnumerator;
    end;
    
    function TBjmInterfacedList<T>.Add(const Value: T): Integer;
    begin
      Result := FList.Add(Value);
    end;
    

    And then you can do stuff like:

    ISite = interface(IInterface)
      ...
    end;
    ISites = interface(IList<ISite>);
      ...
    end;
    
    var
      for Site in Sites do begin
        ...
      end;
    

    with implementing classes like:

    TSite = class(TBjmInterfacedObject, ISite)
      ...
    end;
    TSites = class(TBjmInterfacedList<ISite>, ISites)
      ...
    end;
    

    Update

    Example project source uploaded to
    http://www.bjmsoftware.com/delphistuff/stackoverflow/interfacedlist.zip

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can we call COM exposed interface methods at runtime one by one? This can
Can I expose a class from another .net namespace as a class in my
Can I access spring bean that exposed using http invoker (server) from GWT application
I know I can expose a class inside a web-module as a restful interface
In the How Can I Expose Only a Fragment of IList<> question one of
can't I expose my methods as webmethods in a winform and have other clients
HI, I have a device that exposes a telnet interface which you can log
I'd like to setup a spring bean (either via interface or bean class). that
This is in C++. So, I'm starting from scratch writing a game engine for
I have a feeling this should be a common requirement, but I can't work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.