title: Inheritance/polymorphism concept
body: <p>I have two binary files that contain a similar type of data so I want to create a unified viewer (TViewer) for both files.
  Some, methods are common for these two file types, some are not. So I created a base class
  TShape, and the from it TCircle and TTriangle.</p>
  
  <p>Pseudo code:</p>
  
  <pre><code>TShape = class(TObject)
    function NoOfItems: integer; virtual; abstract; 
  end;
  
  TCircle = class(TShape)
    function NoOfItems: integer; override;     &lt;---- The real implementation 
  end;
  
  TTriangle = class(TShape)
    function NoOfItems: integer; override;        &lt;---- The real implementation 
  end;
  
  TViewer = class(TStringGrid)
    Container: TShape;
  end;
  </code></pre>
  
  <p>And I use it like this:</p>
  
  <pre><code>Procedure Main;
  begin
   if FileType= Circle 
   then (Viewer.Container as TCircle).Load(FileName)
   else (Viewer.Container as TTriangle).Load(FileName);
  
   Caption:= Viewer.Container.NoOfItems;  &lt;---- it calls TShape which is abstract
  end;
  </code></pre>
  
  <p>When I do this it works:</p>
  
  <pre><code>if Viewer.Container is TTriangle 
  then Caption:= (Viewer.Container as TTriangle).NoOfItems
  else ...
  </code></pre>
  
  <p>but I want to do it directly like this:</p>
  
  <pre><code>Caption:= Viewer.Container.NoOfItems;
  </code></pre>
  
  <p>Obviously there is nothing wrong in using <code>is</code> except that I will have to use it in many many places (close to everywhere). There is a nicer way to achieve this unified viewer? </p>
  
  <h2>Update:</h2>
  
  <p>Actually, it may be also a performance problem. My file has a really big number of items (up to billions) so doing so many 'is/as' tests may actually have a real impact on speed.</p>