Board index » delphi » Uses clause, and DCU's

Uses clause, and DCU's

I've been wondering for a while, if adding a Delphi unit like FileCtrl
to more than one of my own units, actually causes the FileCtrl to be
compiled separately each time ?

It woulds seem to be inefficient if FileCtrl was compiled separately
into each DCU, and yet if it is only compiled once, then you would
have thought that Borland would only have required such a unit to be
added the main unit, and the main unit referenced alone.

Perhaps it is the case that adding FileCtrl to a unit's uses clause,
only points to a single compiled object, in which case the addition of
a unit like FileCtrl could be made with abandon  ... or is this
erroneous ?    : )

Thanks !

Simon R Knight

 

Re:Uses clause, and DCU's


Quote
Simon R Knight wrote...

|I've been wondering for a while, if adding a Delphi unit like
FileCtrl
|to more than one of my own units, actually causes the FileCtrl to be
|compiled separately each time ?

No.
Delphi will only compile in what you actually use  (call) in the unit.
(example: if e.g. 25 procedures are defined in FileCtrl, and you call
 3 of them in unit b, and the same 3 in unit c, then only the code for
these 3
procedures  will be compiled into the final exe.)

|
|It woulds seem to be inefficient if FileCtrl was compiled separately
|into each DCU, and yet if it is only compiled once, then you would
|have thought that Borland would only have required such a unit to be
|added the main unit, and the main unit referenced alone.
|
The idea behind units is to have selfcontained, well-defined  chunks
of code and data that can be used in *many* projects, without being
dependent on some
declaration in the  main unit (.DPR)

|Perhaps it is the case that adding FileCtrl to a unit's uses clause,
|only points to a single compiled object, in which case the addition
of
|a unit like FileCtrl could be made with abandon  ... or is this
|erroneous ?    : )
|
I think it is, but ehhr.. I don't quit understand the question...

Regards,
Dirk Claessens
______________________________________________
Home   : <dirk.claess...@village.uunet.be>
Office : <dirk.claessens...@belgium.agfa.com>
Nothing will come of nothing.
Dare mighty things. (William Shakespeare)
______________________________________________

Re:Uses clause, and DCU's


On Sat, 14 Feb 1998 13:47:57 GMT, s...@bigfoot.com (Simon R Knight)
wrote:

Quote
>I've been wondering for a while, if adding a Delphi unit like FileCtrl
>to more than one of my own units, actually causes the FileCtrl to be
>compiled separately each time ?
>It woulds seem to be inefficient if FileCtrl was compiled separately
>into each DCU, and yet if it is only compiled once, then you would
>have thought that Borland would only have required such a unit to be
>added the main unit, and the main unit referenced alone.

>Perhaps it is the case that adding FileCtrl to a unit's uses clause,
>only points to a single compiled object, in which case the addition of
>a unit like FileCtrl could be made with abandon  ... or is this
>erroneous ?    : )

You've wandered off the track, m'lad. One .pas file (only) is compiled
into one .dcu file. If your MyUnit.pas calls a procedure found in
FileCtrl.pas, the compiler will compile MyUnit.dcu and FileCtrl.dcu,
and MyUnit.dcu will NOT contain anything taken from FileCtrl, except
references to FileCtrl.dcu. To create the .exe, the compiler will
simply copy the referenced procedure out of FileCtrl.dcu into your
exe.

Say (for the sake of clarity) that FileCtrl.pas contains (fictitious)
procedures W, X, Y and Z. Say your project includes units A, B and C,
all of which use FileCtrl.

Say your unit A calls procedures X and Y, your unit B calls procedures
Y and Z, and your unit C calls procedures X and Z (X, Y and Z are all
called twice, by two different units, and W is never used).

FileCtrl.dcu will contain the compiled versions of W, X, Y and Z.

Your .exe file will only contain a single copy of X, a single copy of
W, and a single copy of Z.

Incidentally, the compiler will only physically compile FileCtrl.pas,
it is smart enough to realize that there is no sense in compiling the
same unit three times, even if three of your units make reference to
it.

Re:Uses clause, and DCU's


On Sat, 14 Feb 1998 22:27:52 +0100, "Dirk Claessens"

Quote
<Dirk.Claess...@village.uunet.be> wrote:

>>Simon R Knight wrote...
>>I've been wondering for a while, if adding a Delphi unit like
>>FileCtrl
>>to more than one of my own units, actually causes the FileCtrl to be
>>compiled separately each time ?

>No.
>Delphi will only compile in what you actually use  (call) in the unit.
>(example: if e.g. 25 procedures are defined in FileCtrl, and you call
> 3 of them in unit b, and the same 3 in unit c, then only the code for
>these 3
>procedures  will be compiled into the final exe.)

I see ...

Quote

>>It woulds seem to be inefficient if FileCtrl was compiled separately
>>into each DCU, and yet if it is only compiled once, then you would
>>have thought that Borland would only have required such a unit to be
>>added the main unit, and the main unit referenced alone.

>The idea behind units is to have selfcontained, well-defined  chunks
>of code and data that can be used in *many* projects, without being
>dependent on some
>declaration in the  main unit (.DPR)

That's interesting !  ... so project DCU's can be distributed similar
to component DCU's. Because of references to the compilers "linking"
process, I never thought of them as independently portable. I guess I
could create a project DCU for - say - some encryption routines, and
simply add the DCU to later projects, avoiding accidental code
changes, and bypassing the normal .pas in a build-all. Great !

Quote

>Perhaps it is the case that adding FileCtrl to a unit's uses clause,
>only points to a single compiled object, in which case the addition
>of
>a unit like FileCtrl could be made with abandon  ... or is this
>erroneous ?    : )

>I think it is, but ehhr.. I don't quit understand the question...

I originally imagined that if a Delphi unit was added to a units
clause, that it would be compiled in its entirety, and as a unit is an
object, thought of the compiled unit as an object also.

Thanks for the clarification !

Simon R Knight

Re:Uses clause, and DCU's


Quote
Simon R Knight wrote...

|On Sat, 14 Feb 1998 22:27:52 +0100, "Dirk Claessens"

Quote
|<Dirk.Claess...@village.uunet.be> wrote:

[snip]
|>Perhaps it is the case that adding FileCtrl to a unit's uses clause,
|>only points to a single compiled object, in which case the addition
|>of
|>a unit like FileCtrl could be made with abandon  ... or is this
|>erroneous ?    : )
|>
|>I think it is, but ehhr.. I don't quit understand the question...
|>
|
|I originally imagined that if a Delphi unit was added to a units
|clause, that it would be compiled in its entirety, and as a unit is
an
|object, thought of the compiled unit as an object also.
|

Just one more correction : A unit is *not* an object. A unit *may* but
does not *has* to contain the class definition(s) of (an) object(s).
An object is an instantiated class, or formally:  MyObject :=
MyUnit.TMyObject.Create();

Regards,
Dirk Claessens
______________________________________________
Home   : <dirk.claess...@village.uunet.be>
Office : <dirk.claessens...@belgium.agfa.com>
Nothing will come of nothing.
Dare mighty things. (William Shakespeare)
______________________________________________

Other Threads