title: How do I check whether an interfaced object implements another interface?
body: <p>I have these interface declarations:</p>
  
  <pre><code>IListener = interface
    procedure HandleEvent(AEvent: TMyEvent);
  end;
  
  IExtendedListener = interface(IListener)
    ['{85A3456A-D5E5-4F37-ABDD-A75A7B3B494C}']  // required by GetInterface
    procedure HandleExtendedEvent(AExtendedEvent: TMyExtendedEvent);
  end;
  </code></pre>
  
  <p>Given an interface reference for something that implements <code>IListener</code>, how can I check whether it also implements <code>IExtendedListener</code>? I'm using the code below code because it is a compile time error to do something like <code>if Listener is IExtendedListener then ...</code>.</p>
  
  <pre><code>TSomeClass.Notify(AEvent: TMyExtendedEvent);
  var
    Listener: IListener;
    ExtListener: IExtendedListener;
    Obj: TObject;
  begin
    for Listener in FListeners do
    begin
      // works but smells funny
      Obj := Listener as TObject;
      Obj.GetInterface(IExtendedListener, ExtListener);
      if Assigned(ExtListener) then
        ExtNotifyee.HandleExtendedEvent(AEvent);
    end;
  end;
  </code></pre>