views:

1170

answers:

3

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!

+5  A: 

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.

Jim McKeeth
Jim, where is the option to treat warnings as errors?
Jamie
OK, I can't find it. I thought it was there, but I may be incorrect (happens occasionally)
Jim McKeeth
Ah, so you found it: http://stackoverflow.com/questions/268062/
Jim McKeeth
+1  A: 

There is no way to make that warning into an error. In Delphi 2009 you can make treat all warnings as errors.

PS: It is an error in Delphi for .Net

Lars Truijens
+1  A: 

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.

Liron Yahdav