简体   繁体   English

在单个DCU中编译多个单元

[英]Compiling multiple units in a single DCU

Coming from a .NET background, now working with Delphi. 来自.NET背景,现在正在使用Delphi。 In .NET, I used to have a separate library project with many classes seperated into distinct files. 在.NET中,我曾经有一个单独的库项目,其中许多类分隔成不同的文件。 When I compiled this project, I got a single DLL file. 当我编译这个项目时,我得到了一个DLL文件。

However, I am not able to do that in Delphi. 但是,我无法在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. 当我编译我的项目时,我的项目中的每个单元都有一个DCU文件(我相信这相当于一个.NET DLL?)。

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. 我想只有一个DCU文件用于我所有不同单元的类。 Is there a way to achieve what I want to do? 有没有办法实现我想做的事情? How do you deal with these DCUs? 你如何处理这些DCU?

.DCU (Delphi Compiled Unit) files are binary files that are used between compiling source (text) and linking the executable. .DCU (Delphi编译单元)文件是在编译源(文本)和链接可执行文件之间使用的二进制文件。 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. 它们由编译器创建,在内存中连接在一起,与启动代码结合并由链接器放入实际的可执行文件(.EXE / .DLL / .BPL)。

.DCU files are not .DLL (Dynamic Link Library) files, although Delphi can combine one or more .dcu file and link to a .DLL . .DCU文件不是.DLL (动态链接库)文件,尽管Delphi可以将一个或多个.dcu文件和链接组合到.DLL

The number of .dcu files is meaningless most of the time; 大多数时候.dcu文件的数量毫无意义; it's the .pas source files you need to be concerned about, and there is one of them for each source unit you create. 它是您需要关注的.pas源文件,并且您创建的每个源单元都有一个。 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. 在uses子句中,每个.pas文件总是有一个.dcu文件,还有一个用于编译自己的源文件。

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; 将组件安装到IDE中的Component Palette中时,.dcu放在.BPL (Borland包库)中,这是一种特殊类型的DLL; that BPL, or package, file is then loaded as executing code into the IDE. 然后将BPL或包文件作为执行代码加载到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. 在BPL中执行的代码实际上创建了一个按钮,并允许它在表单编辑器中显示和操作。

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. 当您构建可执行文件(并且不使用运行时包)时,DCU文件将链接到您的应用程序,并且一旦创建了可执行文件(.EXE)文件,则不再需要原始.pas文件或.dcu文件。 (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.) (直到,也就是说,您需要对可执行文件进行更改,在这种情况下修改.pas文件,编译器会创建一个新的.dcu ,并且链接器将它们组合在一起以创建新的.exe文件。)

.DCU files are intermediate files used during the development process. .DCU文件是开发过程中使用的中间文件。

.DCU files are not shipped with the final executable .EXE file .DCU文件不随最终的可执行文件.EXE文件一起提供

Yes, its posible to build a .DLL with Delphi and make a (Delphi-made) .EXE use it. 是的,它可以用Delphi构建一个.DLL并使(Delphi制造的).EXE使用它。 A regular C/C++ .EXE can also use a Delphi .DLL if certain conventions are followed. 如果遵循某些约定,常规C / C ++ .EXE也可以使用Delphi .DLL。

If you want to ship a collection of procedures/classes to a library, a .DLL or (a more Delphi native) .BPL can be made. 如果要将一组过程/类发送到库,可以创建.DLL或(更多Delphi本机).BPL。

Every time a .PAS file is modified and recompiled it's correspondant .DCU file is also rebuild. 每次修改.PAS文件并重新编译它都是对应的.DCU文件也会重建。

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. 在某些开发环境中,.DCU文件提供给开发人员而不是源.PAS文件,当他们不想关闭源代码时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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