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

  • SEARCH
  • Home
  • 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 6706805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:33:49+00:00 2026-05-26T07:33:49+00:00

Can an inherited Interface be used as a key in TDictionary? //! Note the

  • 0

Can an inherited Interface be used as a key in TDictionary?

//! Note the inheritance of the interfaces
ILoggingProvider = interface
  procedure Log(AMessage : string);
end;

IHTTPLoggingProvider = interface(ILoggingProvider)      
  function Login(AUserName : string; APassword : string) : boolean
end;

ILiveLoggingProvider = interface(ILoggingProvider)
  function ConnectMonitor : boolean
end;

var
  loggers : TDictionary<ILoggingProvider,TObject>;

...

loggers.add(ILoggingProvider, TSomeLogger.Create());
loggers.add(IHTTPLoggingProvider , TSuperLogger.Create()); //fails!
loggers.add(ILiveLoggingProvider , TAnotherLogger.Create()); //fails!


 ... //and the use them selectively

if loggers.ContainsKey(IHTTPLoggingProvider ) then
  loggers.Items[IHTTPLoggingProvider].Log('Good bye world!');

... //and like this

var

  theLogger : IHTTPLoggingProvider;

if loggers.ContainsKey(IHTTPLoggingProvider ) then
begin
  theLogger := IHTTPLoggingProvider(loggers.Items[IHTTPLoggingProvider]);
  if theLogger.Login('billy', 'bones') then
    theLogger.Log('some message');
end;
  • 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-26T07:33:50+00:00Added an answer on May 26, 2026 at 7:33 am

    Following on from my comment, here is how I think this could be implemented:

    type
      ILoggingProvider = interface
        ['{30598F45-1230-4208-B1A5-E1D2DA8F6D40}']
        procedure Log(AMessage : string);
      end;
    
      IHTTPLoggingProvider = interface(ILoggingProvider)
        ['{CFA01514-AC44-4E30-971B-115986B37D26}']
        function Login(AUserName : string; APassword : string) : boolean;
      end;
    
      ILiveLoggingProvider = interface(ILoggingProvider)
        ['{6EA68BEF-8D78-4FDF-AACD-1D164A272758}']
        function ConnectMonitor : boolean;
      end;
    
      TLoggingProvider = class(TInterfacedObject, ILoggingProvider)
        procedure Log(AMessage : string);
      end;
    
      THTTPLoggingProvider = class(TInterfacedObject, ILoggingProvider, IHTTPLoggingProvider)
        procedure Log(AMessage : string);
        function Login(AUserName : string; APassword : string) : boolean;
      end;
    
      TLiveLoggingProvider = class(TInterfacedObject, ILoggingProvider, ILiveLoggingProvider)
        procedure Log(AMessage : string);
        function ConnectMonitor : boolean;
      end;
    
    procedure Main;
    var
      loggers : TDictionary<TGUID,ILoggingProvider>;
      theLogger : IHTTPLoggingProvider;
    begin
      loggers := TDictionary<TGUID,ILoggingProvider>.Create;
      try
        loggers.add(ILoggingProvider, TLoggingProvider.Create);
        loggers.add(IHTTPLoggingProvider, THTTPLoggingProvider.Create);
        loggers.add(ILiveLoggingProvider, TLiveLoggingProvider.Create);
    
        if loggers.ContainsKey(IHTTPLoggingProvider) then
          loggers.Items[IHTTPLoggingProvider].Log('Good bye world!');
    
        if loggers.ContainsKey(IHTTPLoggingProvider) then
        begin
          theLogger := loggers.Items[IHTTPLoggingProvider] as IHTTPLoggingProvider;
          if theLogger.Login('billy', 'bones') then
            theLogger.Log('some message');
        end;
      finally
        loggers.Free;
      end;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose, if my class inherited from an interface, can super() be used in method
Today I happens to find that one C# class can inherit one interface both
If an interface inherits IEquatable the implementing class can define the behavior of the
How can I use an inherited class of a triangulation in the context of
I have inherited a c# class 'Button' (which I can't change) which clashes with
In the inherited class I use the base constructor, but I can't use the
I have a set of interfaces which are used in close conjunction with particular
Java docs says the following about Set interface, can someone please help me understand
In many iOS books and tutorials they demonstrate how in interface builder you can
In Java, you can define an interface as a class with no actual code

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.