ianhinson wrote:
> Due to starting a major new version of a program, and wanting to
> leave the existing version "as is", I created a new folder and copied
> source files into the new folder.
>
> At first I only copied the application files (.dpr, .dof, .cfg. res)
> and the .pas/.dfm files referred to in the Project Manager.
> Although some other custom .pas are needed (that are not included in
> the Program Manager) I left them out of the initial copy just so that
> the compiler could "tell" me which units I need so that I wouldn't be
> copying across old units that are no longer used.
>
> To my surprise the newly copied application files compiled first
> time - even though I knew there must be SOME pas files I did not copy
> across.
> I found that it compiled because units in the new folder where using
> units in the old folder (by doing ctrl-click to see where it was
> getting some items from that should've been undefined).
>
> I had to re-name the old folder in a desperate attempt to hide the
> old units (which worked) and proceed as I had originally expected.
>
> The weird thing is that there is NO reference to the old folder at
> all that I can find. Not in the Search Path, or any of the
> application files (.dpr, .dof, .cfg), or any of the pas files.
>
> How would it be finding my units in a completely different folder?
> Both of the source file folders are directly under "Delphi7\Projects".

The DPR file contains references to all the units that are members of your
project. Look in it and you'll see. The references might be relative
paths, but they might also be absolute paths. If they're absolute, then
it's obvious how the compiler is finding the units you don't want it to
find -- you're telling it exactly where they are.

Units that aren't members of your project are found with the library path
and the search path.

I recommend that any project should contain all and only those units that
the compiler should compile when building that project. And no unit should
be a member of more than one project. If you have units that are used by
multiple projects, then put that unit in a package. When you want to
recompile that shared unit, recompile the package. That way, you're less
likely to accidentally break one project by changing the shared unit
during an editing session of some other project. Instead, you'll have to
open the package, thereby reminding yourself that you're working on shared
code.

This doesn't mean you need to use run-time packages. In this case,
packages are just a way of structuring your projects.

Keeping everything separate like this lets you do another organizational
task, which is to keep source files and compiled files in separate
directories. I compile _all_ my DCU files into a single folder (one per
Delphi version). My search path consists of only that directory. This way,
the compiler never accidentally finds the source to a unit I don't want it
to find. This is because all the source I want it to find it mentioned
explicitly in the project file -- the compiler is only compiling units
that actually belong to the project I'm working on.

-- 
Rob


Reply via email to