How to create a sub-library in a "uses" clause?

When I use Delphi 2006, it was:

uses System, SysUtils, StrUtils, Windows, Dialogs, WinApi; 

But lately we can use:

  uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics; 

How does this change work? Did they System.pas into System.*.pas or did they create a new sentence to separate functions by type in one library?

How can I change the old libraries to work as follows? I want to do something like: MyLib.Logic, MyLib.Arrays, MyLib.NetWork, etc.

+4
source share
3 answers

What you are facing is called Unit Names . The different names RTL and VCL have been changed to better distinguish which units are platform-specific and which are cross-platform. Not only are the node names using namespaces that have been since Delphi.NET was introduced, but now even the names of the element files themselves are now also replaced with names, which is new.

If you are not writing cross-platform code, you are advised to use the new syntax:

 uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics 

However, if you want to write cross-platform code or just have legacy code that you need to support, continue using the original syntax:

 uses System, SysUtils, StrUtils, ...; 

And then make sure that the prefixes are "Winapi", "System", "Vcl", "Fmx", etc. are included in the "Scope Identifiers" field of the project parameters as necessary.

+3
source

Just open your old files in the idea, and rename it in the project manager. It will automatically change the name of the device inside the file.

After that, open and recompile your old projects to make sure that you are referencing the correct device names.

The only advantage of these points over something like underscores seems to be that you can get a list of the corresponding โ€œsubclassesโ€ at the end of the code.

The part in front of any dots should not be called a "namespace" because it does not work as one.

+4
source

They are called namespaces , and they have been around since Delphi 7 or so while they were preparing for the release of Delphi 8 (Delphi for .NET). They have been added to support .NET parties. They are described in Using Namespaces with Delphi .

+3
source

All Articles