Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 226
Karl-Otto Rosenqvist Avatar asked Sep 17 '08 09:09

Karl-Otto Rosenqvist


2 Answers

Delphi 2009 has the option to make warnings into failures. That would do what you want to do as far as making it fail.

To prevent the implicit importing you need to import it explicitly, or remove the unit that is implicitly importing it.

like image 66
Jim McKeeth Avatar answered Oct 05 '22 19:10

Jim McKeeth


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.

like image 43
Liron Yahdav Avatar answered Oct 05 '22 19:10

Liron Yahdav