Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The reason you cannot use <code>as</code> in your code is that your class does not explicitly list <code>IInterface</code> in its list of supported interfaces. Even though your interface derives from <code>IInterface</code>, unless you actually list that interface, your class does not support it.</p> <p>So, the trivial fix is to declare your class like this:</p> <pre><code>TMyClass = class(TObject, IInterface, IMyInterface) </code></pre> <p>The reason that your class needs to implement <code>IInterface</code> is that is what the compiler is relying on in order to implement the <code>as</code> cast.</p> <p>The other point I would like to make is that you should, in general, avoid using interface inheritance. By and large it serves little purpose. One of the benefits of using interfaces is that you are free from the single inheritance constraint that comes with implementation inheritance. </p> <p>But in any case, all Delphi interfaces <a href="http://docwiki.embarcadero.com/RADStudio/en/Object_Interfaces#IInterface_and_Inheritance">automatically inherit from <code>IInterface</code></a> so in your case there's no point specifying that. I would declare your interface like this:</p> <pre><code>IMyInterface = interface ['{B84904DF-9E8A-46E0-98E4-498BF03C2819}'] procedure InterfaceMethod; end; </code></pre> <p>More broadly you should endeavour not to use inheritance with your interfaces. By taking that approach you will encourage less coupling and that leads to greater flexibility.</p>
    singulars
    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