title: calling methods of a class inherited form an interface and another ancestor
body: <p>I have problem with implementing relation between some classes. I got three different classes serving three different forms. All these classes speak in same language, so they are inherited from same class called <code>TAncestorServer</code>. Let’s call its descendants <code>TForm1Server</code>, <code>TForm2Server</code>, and <code>TForm3Server</code>. <code>TAncestorServer</code> contains an abstract method called <code>Function1</code>, so <code>TForm1</code>, <code>TForm2</code>, and <code>TForm3</code> can call it with no problem through their own classes inherited from it, they have an access to the classes through a property named <code>Server</code>. But the problem is about another form called <code>TForm4</code>! It’s very similar to other forms but it’s not independent like them. It works with <code>TForm2Server</code> or <code>TForm3Server</code>. Still not a problem, but imagine another method like <code>Function2</code> which is declared in <code>TForm2Server</code> and <code>TForm3Server</code>, <code>TForm4</code> needs to call them. I can go like this:</p>
  
  <pre><code>if Server is TForm2Server then
     TForm2Server(Server).Function2
  else if Server is TForm3Server then
    TForm3Server(Server).Function2;
  </code></pre>
  
  <p>But it can turn in an infinite if-else clause! So I thought something like multiple-inheritance may help here. I declared an interface called <code>IForm4Server</code> which contains <code>Function2</code>. So <code>TForm2Server</code> and <code>TForm3Server</code> inherit from both <code>TAncestorServer</code> and <code>IForm4Server</code>. I thought something like this could work:</p>
  
  <pre><code>If Server is IForm4Server then
    IForm4Server(Server).Function2;
  </code></pre>
  
  <p>But compiler doesn’t think so, it says that  it’s not a valid type cast, because <code>TAncestorServer</code> is not <code>IForm4Server</code>, which is absolutely right. <code>TForm1Server</code> has no idea about implementing <code>Function2</code> and has to leave it blank. I can’t declare <code>TForm4.Server</code> as <code>IForm4Server</code> too, because <code>Function1</code> represents a huge number of methods and properties, however I still can’t type cast <code>IForm4Server</code> to <code>TAncestorServer</code>.</p>
  
  <p>As a solution I can define two different properties in <code>TForm4</code> like <code>GeneralServer: TAncestorServer</code> and <code>Form4Server: IForm4Server</code> and then assign same instance of <code>TForm2Server</code> or <code>TForm3Server</code> to them, but I don’t feel good about it. How should I do this? Is there any standard pattern for it?</p>