X1033 Unit '%s' implicitly imported into package '%s' (Delphi)

From RAD Studio
Jump to: navigation, search

Go Up to Error and Warning Messages (Delphi)


This warning indicates that a unit has been implicitly linked into the package currently being compiled. Normally, units are involved in a package in one of two ways:

  • Explicitly imported via the "Contains" folder
  • Part of another package specified in the "Requires" folder

If a unit needed for compilation is not found in either the "Contains" folder or within a package specified in the "Requires" folder, the unit is implicitly imported as if it were included in the "Contains" folder.

This warning signals the programmer to consider explicitly adding the unit to the package or adding a reference to a package containing the missing unit.

To prevent this problem in the future, you need to add the .dcp file (which contains the compile and link information for the package) to either the Requires or Contains clause/folder:

  • The Requires folder typically refers to other packages that contain units needed to compile this package. These packages can be from Delphi, such as the RTL package containing the System unit, SysUtils unit, and so on, or other packages created by the programmer containing user-defined units.
  • The Contains folder involves the units to be included into the package, not counting units found in other packages listed in the "Requires" folder.

Fixing the Problem

In the Code Editor, you can add units to the "Requires" and "Contains" clauses by editing your code as necessary. In the Project Manager, you can add units to the "Requires" and "Contains" folders as described here.

To add a reference to the "Requires" folder in the Project Manager

  1. Right-click the "Requires" folder.
  2. Select Add Reference from the context menu.
  3. On the Add dialog, select the appropriate .dcp file or just type the referencing project .dcp file name if the file is in the search path.
  4. Then the .dcp will be listed in the "Requires" folder for the project.

To add a unit to the "Contains" folder in the Project Manager

  1. Right-click the "Contains" folder.
  2. Select either:
    • Add New > Unit from the context menu to add an empty unit in the Contains folder (the Code Editor displays the template for the unit code.)
    • Add from the context menu to display the Open dialog. Select the .pas file for the unit you want to add.

Example

For example, in the following program, Classes uses (either directly or indirectly) consts, TypInfo, and SysUtils.

package Produce;
  contains Classes;
end.

You get a warning message for each of those used units.

The following program explicitly names all those units that will be imported into the package in the contains clause to fix this issue:

package Solve;
  contains consts, TypInfo, SysUtils, Classes;
end.

See Also