我什么时候应该添加对 Delphi 项目的文件引用?

发布于 2024-09-03 13:49:54 字数 346 浏览 5 评论 0原文

标准 VCL 文件(如对话框、StringUtils 等)的单元文件从未在项目 DPR 文件中引用。但是我什么时候应该添加对 DPR 文件的引用? 现在我有自己的源文件和自己的组件源。

Ravereport、Devexpress、Indy、Gnostice 等的源文件怎么样? 我想要尽可能快的 codeinsight,但当然我不想让 DPR 文件变得臃肿。我使用 Delphi 2007

有关相关问题,另请参阅此问题

问候

Unit files for standard VCL files like Dialogs, StringUtils etc is never referenced in a projects DPR-file. But when should I add a reference to the DPR-file ?
Now I have own sourcefiles and source of own components.

What about source files for Ravereport, Devexpress, Indy, Gnostice etc ?
I want as fast codeinsight as possible, but of course I do not want to add bloat to the DPR-file. I use Delphi 2007

See also this question for a related issue.

Regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我不咬妳我踢妳 2024-09-10 13:49:54

我总是将项目使用的所有我自己的代码单元添加到 dpr use 子句中。仅根据需要添加 VCL 单元和来自第三方库的单元。因此,项目的库路径仅包含 vcl 和第三方库的路径。

虽然项目不需要进行编译以将所有单元添加到项目的 dpr 中,而且这需要一些额外的工作,但它使依赖关系变得明确,并有助于避免因隐式使用可能潜伏的“旧”dcu 造成的问题在库路径上。

当不同项目的单位名称相同但内容不同时,它也会有所帮助。对于共享单元使用的项目特定代码很有用。共享单元仅使用“unit1”,dpr 会说明是哪个单元。比使用库路径更明确且更不易出错。

项目的 dpr 还始终包含所有使用的组件(vcl 或第三方)的路径。我的环境选项中的库路径为空。它甚至不包含 vcl 的路径。这可能有点 ott(过分),但是嘿,很容易检查...

同样,这有助于使依赖关系明确,并且当您在路径中使用自己的环境变量时,例如 $(MVC)\ComponentName \Source,当将代码传送到另一台机器时它也很有帮助。我唯一需要做的就是复制该批次(或将其放在 USB 记忆棒上)并在 Delphi IDE 中设置 MVC 环境变量。我可以放心,在构建我的项目时,另一台计算机上安装的任何内容都不会干扰。

I always add all my own code units a project uses to the dpr uses clause. VCL units and units from third party libraries are only added as needed. The project's library path therefore only contains paths to the vcl and third party libraries.

While it isn't necessary for the project to compile to add all your units to the project's dpr, and it is a bit of extra work, it makes dependencies explicit and helps avoid problems caused by implicit use of possibly "old" dcu's lurking about on the library path.

It also helps when you have the same unit name with different content for different projects. Useful for project specific code used by a shared unit. The shared unit simply uses "unit1" and the dpr says which one. More explicit and less error prone than using the library path.

The project's dpr also always includes the path's to all components used, vcl or third party. The library path in my environment options is empty. It does not even contain the paths to the vcl. That may be a bit ott (over the top), but hey it is easy to check...

Again, this helps to make dependencies explicit and when you use your own environment variable in the paths, for example $(MVC)\ComponentName\Source, it also helps when carrying your code to another('s) machine. The only thing I need to do is copy the lot over (or carry it on an USB stick) and set the MVC environment variable in the Delphi IDE. And I can rest assured that whatever is installed on the other machine won't interfere when building my project.

謸气贵蔟 2024-09-10 13:49:54

您只需要(并且应该)添加对 DPR 中实际使用的内容的引用。例如,如果您正在编写一个测试项目(包含项目测试代码的项目),您可以添加 GuiTestRunner 或 TextTestRunner (对于 DUnit):

program MyTest;

uses
  all.pas in 'src\all.pas',
  your.pas in 'src\your.pas',
  project.pas in 'test\projects.pas',
  units.pas in 'test\units.pas',
  TextTestRunner;

var
  R: TTestResult;

begin
  R := TextTestRunner.RunRegisteredTests;
  ExitCode := R.ErrorCount + R.FailureCount;
end.

否则,对于 Indy 或其他第 3 方单位,只需在实际使用它们的单位中引用它们即可。

You need only (and should only) add references to things in your DPR that your DPR actually uses. For instance, if you're writing a test project (a project that contains your test code for your project) you might add GuiTestRunner or TextTestRunner (for DUnit):

program MyTest;

uses
  all.pas in 'src\all.pas',
  your.pas in 'src\your.pas',
  project.pas in 'test\projects.pas',
  units.pas in 'test\units.pas',
  TextTestRunner;

var
  R: TTestResult;

begin
  R := TextTestRunner.RunRegisteredTests;
  ExitCode := R.ErrorCount + R.FailureCount;
end.

Otherwise, with Indy or other 3rd party units, just reference them in the units that actually use them.

泪眸﹌ 2024-09-10 13:49:54

我向 .dpr 添加尽可能少的单位。这是因为我不喜欢在那里放置硬编码路径,并且使用相对路径有时会出现奇怪的错误(就像这里描述的),让我相对自由地移动代码。

然而,我实际上并没有通过项目检查器浏览太多单元,我主要通过打开单元来使用 ctrl-enter 来导航单元。我的同事必须经常适应这一点,因此对于喜欢鼠标的团队来说这可能不可行。

I add as little units to the .dpr as possible. This because I don't like putting hardcoded paths there, and with relative paths there will be strange errors sometimes (like described here) and leaves me relatively free to move around code.

However I don't really browse units much via the project inspector, I navigate mostly units with ctrl-enter by opening units. My coworker had to get used to this a lot, so it might not be feasable for a mouse-happy team.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文