R – Prevent implicit import of units in Delphi packages


Is there a way to prevent packages in Delphi to implicitly import units that are not listed in the "Contains" list? I'm looking for a compiler directive that makes the build to fail if it tries to do an implicit import.

Problems occur when you install a package into the IDE that implicitly imports unit A and then you try to install another package that really contains unit A and the IDE tells you that it cannot install that package because unit A is already contained in the first package even if it shouldn't be!

Best Solution

If you're on a version of Delphi that's older that 2009, you can make the warning cause an error by using DDevExtensions (it's free). Once you install it, go to Tools > DDevExtensions - Options and in the "Compiler Enhancements" section select the "Active" check box and "Treat warnings as errors". You can add the warnings you want to not be treated as errors in the memo below that. Unfortunately, in your case, it looks like you just want one warning to be treated as an error, so you'll have to add pretty much every warning except the one about implicit importing to the list, although it's generally good coding practice to resolve all compiler warnings anyways, so you might want to just have all warnings cause errors.

Related Question