Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I add a file reference to a Delphi project?

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

like image 661
Roland Bengtsson Avatar asked May 29 '10 10:05

Roland Bengtsson


3 Answers

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.

like image 130
Marjan Venema Avatar answered Oct 10 '22 22:10

Marjan Venema


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.

like image 38
Frank Shearar Avatar answered Oct 11 '22 00:10

Frank Shearar


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.

like image 1
Marco van de Voort Avatar answered Oct 10 '22 23:10

Marco van de Voort