在Delphi中,我应该将共享单元添加到我的项目中,还可以添加到一个共享的包中吗? [英] In Delphi, should I add shared units to my projects, to a shared package, or neither?

查看:131
本文介绍了在Delphi中,我应该将共享单元添加到我的项目中,还可以添加到一个共享的包中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题类似于这个,但不是重复的,因为我在问这个问题没有讨论的问题。



我有一个客户端-server项目在Delphi 7中,具有以下目录结构:

  \MyApp 
\MyClientApp
\MyServerApp
\lib

有2个实际的Delphi项目(.dpr) MyClientApp和MyServerApp文件夹中有一个。



lib文件夹具有对客户端和服务器应用程序具有通用代码的.pas单元。我想知道的是,如果我应该在客户端和服务器项目中包含这些.pas文件?还是应该在包含这些单元的lib文件夹中创建一个包?或者我应该将.pas文件放在lib文件夹中,而不是将它们添加到任何应用程序/包中?



每种方法的优缺点是什么?哪种方式是最好的?将lib文件夹中的这些单元包含在多个项目中有什么问题吗?



现在,lib文件夹中的单位不是任何应用程序的一部分/包。一个缺点是,当我在Delphi中打开我的客户端应用程序时,例如,我想在项目中的所有文件中搜索一些东西,它也不会在lib文件夹中单位中搜索。我打开这些单位并在所有打开的文件中查找,或使用grep搜索(但我宁愿更好的解决方案)。



我也会非常喜欢一个解决方案,我不必去打开一些单独的包,并重新编译它,当我更改lib文件夹中的这些文件(这是我应该使用一个项目组?)。

解决方案

应用程序之间的共享单元总是在一个破坏另一个应用程序的应用程序中带来不兼容的更改风险。另一方面,这些单位的副本更糟糕,所以你的移动他们到自己的子目录的准备至少增加了一个心理障碍来改变他们,而不考虑其他程序。



关于将它们添加到项目文件中:我通常添加一些我经常从IDE到项目访问(用于扩展或引用)的单元,并将其他单元留给编译器选择使用搜索路径。我每个项目都是这样做的,这意味着有些单位可能是几个项目的一部分,为什么不这样呢?



把它们放在一个包里是有道理的,如果你真的想要创建一个基于软件包的应用程序,否则为什么要麻烦?



有关如何组织我的项目和库的更多信息,请参阅 http://www.dummzeuch.de/delphi/subversion/english.html


This question is similar to this one, but not a duplicate because I'm asking about issues not discussed in that question.

I have a client-server project in Delphi 7 with the following directory structure:

\MyApp
  \MyClientApp
  \MyServerApp
  \lib

There are 2 actual Delphi projects (.dpr), one each in the MyClientApp and MyServerApp folders.

The lib folder has .pas units that have common code to the client and server apps. What I'm wondering is if I should include those .pas files in the client and server projects? Or should I create a package in the lib folder which includes those units? Or should I just leave the .pas files sitting in the lib folder and not add them to any app/package?

What are the pros/cons of each approach? Which way is "best"? Is there any issue with having those units from the lib folder be included in more than one project?

Right now the units in the lib folder are not a part of any app/package. One disadvantage of this is that when I have my client app open in Delphi, for example, and I want to search in all files in the project for something, it doesn't also search in the units in the lib folder. I get around this by opening those units and doing a find in all open files, or using grep search (but I'd prefer a better solution).

I would also greatly prefer a solution where I will not have to go and open some separate package and recompile it when I make changes to those files in the lib folder (is this where I should use a project group?).

解决方案

Sharing units between applications always carries the risk of incompatible changes done in one application that breaks the other. On the other hand, making copies of these units is even worse, so your approcach of moving them to their own subdirectory at least adds a psychological barrier to changing them without considering other programs.

As for adding them to the project files: I usually add some units which I frequently access (either for expanding or for reference) from the IDE to the project, and leave others out for the compiler to pick using the search path. I do that on per project basis, that means, some units may be part of several projects, why not?

Putting them into a package only makes sense, if you actually want to create a package based application, otherwise, why bother?

For more info on how I organize my projects and libraries, see http://www.dummzeuch.de/delphi/subversion/english.html

这篇关于在Delphi中,我应该将共享单元添加到我的项目中,还可以添加到一个共享的包中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆