简体   繁体   中英

Compiling multiple units in a single DCU

Coming from a .NET background, now working with Delphi. In .NET, I used to have a separate library project with many classes seperated into distinct files. When I compiled this project, I got a single DLL file.

However, I am not able to do that in Delphi. I have many classes, each in their own file with their own unit name (I did not find a way to have multiple files with the same unit name). When I compile my project, I have one DCU file (I believe this is the equivalent of a .NET DLL?) for each unit in my project.

The problem is that I don't want to have that many files! I would like to have only one DCU file for all of my classes that are in distinct units. Is there a way to achieve what I want to do? How do you deal with these DCUs?

.DCU (Delphi Compiled Unit) files are binary files that are used between compiling source (text) and linking the executable. They're created by the compiler, joined together in memory, combined with the startup code and put into an actual executable (.EXE/.DLL/.BPL) by the linker.

.DCU files are not .DLL (Dynamic Link Library) files, although Delphi can combine one or more .dcu file and link to a .DLL .

The number of .dcu files is meaningless most of the time; it's the .pas source files you need to be concerned about, and there is one of them for each source unit you create. They're re-created as needed if the source file is changed, or used in their compiled state if the source isn't changed for link speed. There is always one .dcu file per .pas file in your uses clause, plus one for your own source being compiled.

When you install a component into the Component Palette in the IDE, the .dcu is placed in a .BPL (Borland Package Library), which is a special type of DLL; that BPL, or package, file is then loaded as executing code into the IDE. This is how a button is visually displayed on a form at designtime; the code executing in the BPL actually creates a button and allows it to be displayed and manipulated in the Form Editor.

When you build an executable (and don't use runtime packages), the DCU file is linked into your application, and once the executable (.EXE) file is created neither the original .pas file or the .dcu is needed any longer. (Until, that is, you need to make changes to the executable, in which case the .pas file is modified, the compiler creates a new .dcu , and the linker combines them to create a new .exe.)

.DCU files are intermediate files used during the development process.

.DCU files are not shipped with the final executable .EXE file

Yes, its posible to build a .DLL with Delphi and make a (Delphi-made) .EXE use it. A regular C/C++ .EXE can also use a Delphi .DLL if certain conventions are followed.

If you want to ship a collection of procedures/classes to a library, a .DLL or (a more Delphi native) .BPL can be made.

Every time a .PAS file is modified and recompiled it's correspondant .DCU file is also rebuild.

In certain development environments, .DCU files are supplied to the developers instead of the source .PAS files, when they don't want to diclose the source code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM