Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/IDE/Refactoring/Extract Interface    [ Add a report in this area ]  
Report #:  88817   Status: Open
Extract Interface produces declarations in wrong order
Project:  Delphi Build #:  15.0.3890.34076
Version:    15.0 Submitted By:   Bob Swart
Report Type:  Basic functionality failure Date Reported:  10/10/2010 8:07:39 AM
Severity:    Infrequently encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All platforms Internal Tracking #:   280783
Resolution: None (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
Given class TBase with a derived class TDerived, if we extract an interface from TBase, then the result is code that will no longer compile.

The TBase class and IBase interface are declared after TDerived, and as a result TDerived no longer knows about the TBase base class (eventhough it's forward declared at the top, TBase is not complete, to TDerived cannot descent from it).
Steps to Reproduce:
Start with the following code unit in file uContact.pas


unit uContact;
interface

type
  TContact = class abstract
  strict private
    procedure SetName(val : String);
  strict private
    function GetName : String;
  public
    property Name :  String read GetName write SetName;
    procedure Contact(Msg: TMessage);virtual;abstract;
  end;

  TEmailContact = class(TContact)
  end;

  TSkypeContact = class(TContact)
  end;

implementation

function TContact.GetName: String;
begin

end;

procedure TContact.SetName(val : String);
begin

end;

end.



Then, for the TContact abstract class, we can extract an Contact interface for example, with the Contact method.

There are a number of problems with the resulting source code. First of all, the order of class definitions is no longer resulting in compilable code. The unit starts with a forward definition of TMessage and TContact, followed by a full definition of TMessage, TEmailContact (derived from the not-yet-complete TContact), TSkypeContact (also derived from the not-yet-complete TContact), followed by the IContact interface and finally the TContact class. In order to fix these issues, we need to move the TEmailContact and TSkypeContact class definitions after the full definition of TContact.
Workarounds
None
Attachment
None
Comments

None

Server Response from: ETNACODE01