title: Different behavior of interface between Delphi 7 and Delphi XE and higher
body: <p>I am having a strange problem of using interface in different versions of Delphi. The following minimized code compiles and runs as expected in Delphi XE and higher but not in Delphi 7. Specificaly, it seems when compiling in Delphi 7, the <code>function TForm1.Load: IMoleculeSubject;</code> does not returns the correct result, i.e., the correct reference to the newly created instance. Could you help to comment about the reason and possible workaround? Many thanks!</p>
  <h3>uInterface.pas</h3>
  <pre><code>    unit uInterface;
      
      interface
      
      type
      
        IMoleculeSubject = interface
        ['{BEB4425A-186C-45DF-9DCE-C7175DB0CA90}']
        end;
      
        TMoleculeSubject = class(TInterfacedObject, IMoleculeSubject)
        end;
      
      implementation
      
      end.
      
  </code></pre>
  <h3>uBusiness.pas</h3>
  <pre><code>    unit uBusiness;
      
      interface
      
      uses
        uInterface;
      
      type
      
        TMoleculeDecorator = class(TMoleculeSubject) 
        private
          FID: Integer;
        public           
          property ID: Integer read FID;
          constructor Create;
        end;
      
      implementation
      
      { TMoleculeDecorator }
      
      constructor TMoleculeDecorator.Create;
      begin
        inherited Create;
      
        FID := Random(100);
      end;
      
      end.
  </code></pre>
  <h3>Unit1.pas</h3>
  <pre><code>    unit Unit1;
      
      interface
      
      uses
        uInterface, uBusiness,
      
        Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, 
        Forms, Dialogs;
      
      type
        TForm1 = class(TForm)
          procedure FormCreate(Sender: TObject);
        private
          function Load: IMoleculeSubject;
        public
        end;
      
      var
        Form1: TForm1;
      
      implementation
      
      {$R *.dfm}
      
      procedure TForm1.FormCreate(Sender: TObject);
      var
        MolSubject: IMoleculeSubject;
      begin
        MolSubject := Load;
      
                // The down-cast is to show the returned result is wrong in Delphi 7!
        Caption := IntToStr(TMoleculeDecorator(MolSubject).ID);
      end;
      
      function TForm1.Load: IMoleculeSubject;   
      var
        MolSubject: IMoleculeSubject;
      begin
        MolSubject := TMoleculeDecorator.Create;
        Result := MolSubject;
      end;
      
      end.
      
      
  </code></pre>