views:

146

answers:

3

Unit files for standard VCL files like Dialogs, StringUtils etc is never referenced in a projects DPR-file. But when should I add a reference to the DPR-file ? Now I have own sourcefiles and source of own components.

What about source files for Ravereport, Devexpress, Indy, Gnostice etc ? I want as fast codeinsight as possible, but of course I do not want to add bloat to the DPR-file. I use Delphi 2007

See also this question for a related issue.

Regards

+1  A: 

You need only (and should only) add references to things in your DPR that your DPR actually uses. For instance, if you're writing a test project (a project that contains your test code for your project) you might add GuiTestRunner or TextTestRunner (for DUnit):

program MyTest;

uses
  all.pas in 'src\all.pas',
  your.pas in 'src\your.pas',
  project.pas in 'test\projects.pas',
  units.pas in 'test\units.pas',
  TextTestRunner;

var
  R: TTestResult;

begin
  R := TextTestRunner.RunRegisteredTests;
  ExitCode := R.ErrorCount + R.FailureCount;
end.

Otherwise, with Indy or other 3rd party units, just reference them in the units that actually use them.

Frank Shearar
My DPR file has a relative short code section and doesn't reference so much units. But the amount of own source files in units and components in the project is huge. Currently there are 483 files added in the dpr's uses section. Mainly because I think it would improve speed of codeinsight. See http://stackoverflow.com/questions/763862/does-it-make-a-difference-if-i-clean-up-my-uses-clause-if-the-removed-units-are-s/764053#764053 http://stackoverflow.com/questions/2776932/adding-files-to-the-dpr-file-vs-project-paths-in-delphi-2010/2777819#2777819
Roland Bengtsson
I agree that you only need what you use in the dpr itself. Don't agree with that being the only thing that should be there. When you frequently switch projects with different library and own code versions, you'll find that making dependencies explicit in the dpr will help you avoid a lot of headaches.
Marjan Venema
@Roland. Don't worry about the number of 483 references in the dpr, we are getting close to 700 in one of our main projects, and are still adding...
Marjan Venema
We've got one where I work that's over 2000, and that's all own code. There's even more in the libraries!
Mason Wheeler
+4  A: 

I always add all my own code units a project uses to the dpr uses clause. VCL units and units from third party libraries are only added as needed. The project's library path therefore only contains paths to the vcl and third party libraries.

While it isn't necessary for the project to compile to add all your units to the project's dpr, and it is a bit of extra work, it makes dependencies explicit and helps avoid problems caused by implicit use of possibly "old" dcu's lurking about on the library path.

It also helps when you have the same unit name with different content for different projects. Useful for project specific code used by a shared unit. The shared unit simply uses "unit1" and the dpr says which one. More explicit and less error prone than using the library path.

The project's dpr also always includes the path's to all components used, vcl or third party. The library path in my environment options is empty. It does not even contain the paths to the vcl. That may be a bit ott (over the top), but hey it is easy to check...

Again, this helps to make dependencies explicit and when you use your own environment variable in the paths, for example $(MVC)\ComponentName\Source, it also helps when carrying your code to another('s) machine. The only thing I need to do is copy the lot over (or carry it on an USB stick) and set the MVC environment variable in the Delphi IDE. And I can rest assured that whatever is installed on the other machine won't interfere when building my project.

Marjan Venema
+1  A: 

I add as little units to the .dpr as possible. This because I don't like putting hardcoded paths there, and with relative paths there will be strange errors sometimes (like described here) and leaves me relatively free to move around code.

However I don't really browse units much via the project inspector, I navigate mostly units with ctrl-enter by opening units. My coworker had to get used to this a lot, so it might not be feasable for a mouse-happy team.

Marco van de Voort
I have never experienced the kind of problems described in the link you gave. In any Delphi version (since D3)... Then again, maybe I am just lucky.
Marjan Venema