mjn
mjn

Reputation: 36644

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

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.

Upvotes: 8

Views: 2387

Answers (1)

pepak
pepak

Reputation: 742

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.

Upvotes: 2

Related Questions