Why does Delphi (dcc32.exe) have an option to set a "Namespace search path"?
Asked Answered
P

1

8

The compiler (dcc32.exe) in Delphi 2007 and higher has an option

-NS<namespaces> = Namespace search path

Is this releated to the compiler options 'Default namespace' and 'Namespace prefixes' in the project options dialog? Search 'path' sounds like a folder (directory) name, so I am not sure what this option is good for.

Phage answered 11/6, 2009 at 6:45 Comment(5)
It's explained in this article.Wingspread
That explains it for dccil.exe, not dcc32.exeSeminary
Yes, but I would assume it applies to dcc32.exe, too.Wingspread
Native doesn't have namespace paths afaik. But maybe it is accepted and ignored for orthogonality.Seminary
Default namespaces work in Delphi Win32: for example, a unit with the name "Lib.Core.Tools" can be included with "uses Tools", if the default namespace is set to "Lib.Core"Phage
O
2

The purpose of this setting is to provide a list of prefixes that are used to search for unit names which are not fully qualified. E.g., in older Delphi versions, you would typically have something like this in your unit's interface section:

uses
  Windows, SysUtils, Classes;

That would instruct the compiler to use the Windows, SysUtils and Classes units when trying to locate unknown identifiers.

In more modern Delphi, it works much the same way, except that the units are no longer called Windows or SysUtils, but rather WinApi.Windows or System.SysUtils. If you use just Windows or SysUtils, they wouldn't be found.

But, of course, no one wants to rewrite all of their source codes to the new unit names. Delphi compiler provides an option to specify the namespaces to be searched by default if an exact unit name is not found. In the example above, we could set the default namespaces to WinApi;System and then all of the units would be properly found, because the Delphi compiler would try to search for Windows (not found), WinApi.Windows (found - go to the next unit), SysUtils (not found), WinApi.SysUtils (not found), System.SysUtils (found - go to the next unit), ..., System.Classes (found - all required units found).

You don't usually deal with this if you use the GUI because the namespace list is a part of the project file and a sensible default is provided. The same applies if you build your applications from command line using msbuild.exe and the project file. But if you use dcc*.exe and the *.dpr, then you do have to provide the namespaces that you want to be applied automatically - and that's what the -NS option is for. In our example, you could use -NSWinApi;System.

Overgrow answered 17/1, 2023 at 18:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.