1

I have a Delphi 6 source code, and I'm migrating it to Delphi 10.2.

In Delphi 6, the delphi library unit name (declared at the uses clause), there is no unit scope name like on Delphi 10.2. Therefore, I need to add unit scope name.

Example:

// In Delphi 6
uses Windows, SysUtils, Dialogs;

// In Delphi 10.2
uses Winapi.Windows, System.SysUtils, Vcl.Dialogs;

How to add unit scope name automatically for all project source files?

I tried the GExperts -> Uses Clause Manager function, it works well, but works only on one file.

GExpert -> Uses Clause Manager

I expect to add unit scope name automatically to all project source files.

Loi
  • 96
  • 6
  • Why not specify the unit scope names in the project options, at least for now? This migration is complicated and you may as well concentrate on the substance first. Deal with unit scope names at the very end. – David Heffernan Mar 23 '19 at 07:55
  • @DavidHeffernan Although I specify the unit scope name in project options, when opening a source file (created by Delphi 6), unit scope name is still not automatically added. It looks like this setting only works for source files that are created on Delphi 10.2. – Loi Mar 23 '19 at 08:51
  • Unit scope names in project don't work that way. Read the docs again. – David Heffernan Mar 23 '19 at 08:54
  • @DavidHeffernan You are right, can specify unit scope names in project options, although compile time will be slower than specify unit scope names in the source code. – Loi Mar 23 '19 at 09:57
  • 1
    It depends on the code for compile time. It's not something that has affected me. In any case, for your migtation project it will be simpler if you keep the changes to a minimum while you migrate. Once you are happy, then consider applying source code wide changes to add unit scope names. – David Heffernan Mar 23 '19 at 10:31
  • @DavidHeffernan Thanks, this comment is really helpful for me. – Loi Mar 23 '19 at 10:57

1 Answers1

1

You can add scopes on a per-project basis under the menu Project->Options, select "Delphi Compiler" then "Unit scope names" in the right pane.

wesson
  • 21
  • 3
  • Your solution is the same as DavidHeffernan. Thank you for giving me an opinion. – Loi Mar 25 '19 at 12:58
  • since Delphi 6 storage of the project has changed. The .dpr file is not alone, and comes with a .dproj file which contains many additional informations including the unit scopes. However, "upgrading" a .dpr only project create an empty dproj without any of the default unit scopes for VCL projects. So, either you need to put by hand for each project the list of default unit scopes for the VCL target, or create an empty VCL project, and add all your forms/units one by one. – wesson Mar 25 '19 at 16:12
  • Thanks for your suport. I open a Delphi 6 project in Delphi 10.2 IDE, *.dproj is created. That file have a node = [Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;System;Xml;Data;Datasnap;Web;Soap;Winapi]. It mean unit scope name is added. So I think it is not different from David Heffernan's solution. – Loi Mar 31 '19 at 10:06
  • Ok. So I'm left with no other suggestion other than thinking that the default set of unit scopes is different depending on the project. So the auto-filled default may need to be completed when upgrading a project from Delphi 6 to XE 10.2+. In anyway, this need to be addressed on a per-project basis. – wesson Apr 02 '19 at 08:42
  • Does not seem to work in Delphi 10.3 ? – oOo Feb 03 '23 at 16:48