Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/Delphi/Interaction with UI    [ Add a report in this area ]  
Report #:  99283   Status: Closed
Auto add missing unit
Project:  Delphi Build #:  16.0.4256.43595
Version:    16.0 Submitted By:   Omar Edgardo Zelaya Medrano
Report Type:  Issue Date Reported:  9/24/2011 9:51:09 AM
Severity:    Extreme corner case Last Updated: 9/25/2011 7:01:37 PM
Platform:    All platforms Internal Tracking #:  
Resolution: Test Case Error (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
When I Compile a project and receive the message : Form 'xxx'  references form 'xxx' declared in unit 'xxx' which is not in your USES list. Do you wish to add?

I select yes and the unit is added to the use clause but the compiler end with errors to the references of the unit automatically added. (Look like the compiler doesn? look the unit added) have to compile again.
Steps to Reproduce:
1. Create a new proyect with Unit1 as mainform.
2. Add a new form to the proyect (Unit2).
3. Add a button to Form1 and on the click event of the button add the code Form2.ShowModal.
as the code above (notice that Unit2 is not in the uses list of Unit1)

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.ShowModal;
end;

end.

4. Compile the code.

It will display the message Form 'Form1' references form 'Form2' declared in unit 'Unit2' which is not in your USES list. Do you wish to add it?

Click on Yes and the compile will finish with the following error:

"[DCC Error] Unit1.pas(28): E2003 Undeclared identifier: 'Form2'"

and the code finish as follows(the uses Unit2 was added by the IDE).

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses Unit2;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.ShowModal;
end;

end.
Workarounds
None
Attachment
None
Comments

Tomohiro Takahashi at 9/24/2011 6:29:07 PM -
Could you please write detailed [Steps] and sample code to reproduce/confirm your issue?

Omar Edgardo Zelaya Medrano at 9/25/2011 6:31:17 PM -
I have added the steps to reproduce it.

Tomohiro Takahashi at 9/25/2011 7:02:34 PM -
This is correct [Steps].
1. try to build
2. compile errors occur FIRST, but build process has not finished.  You can see the result in Message window.
[DCC Error] Unit1.pas(28): E2003 Undeclared identifier: 'Form2'
[DCC Fatal Error] Project1.dpr(5): F2063 Could not compile used unit 'Unit1.pas'
3. IDE adds 'uses Unit2' by clicking [Yes] button explicitly.
4. build process has been done.
5. try to rebuild the project.
6. no build error.

Server Response from: ETNACODE01