简体   繁体   English

Delphi {$ INCLUDE filename}在使用dpr文件的一部分

[英]Delphi {$INCLUDE filename} in uses part of dpr file

I have many Delphi 10 projects that are using the same units, let's call them "commons". 我有许多使用相同单元的Delphi 10项目,我们称它们为“常见”。

When I add anew unit to commons, I have to manually add it to each project. 当我向公共空间添加新单元时,必须手动将其添加到每个项目中。 I have tried adding a {$INCLUDE commons.inc} line into the uses part of each .dpr file: 我尝试将{$INCLUDE commons.inc}行添加到每个.dpr文件的uses部分中:

uses
    Forms,
    {$INCLUDE commons.inc}
    projectUnit1,
    ...;

commons.inc has this content: commons.inc具有以下内容:

common1,
common2,

I can compile a project but cannot manage the units from commons.inc . 我可以编译一个项目,但是不能管理commons.inc的单元。 By manage, I mean Ctrl-F12 , remove from project, etc. 通过管理,我的意思是Ctrl-F12 ,从项目中删除等。

This is from Delphi's help: 这是在Delphi的帮助下:

There is one restriction to the use of include files: an include file can't be specified in the middle of a statement part. 包含文件的使用有一个限制:不能在语句部分的中间指定一个包含文件。 In fact, all statements between the begin and end of a statement part must exist in the same source file. 实际上,语句部分开始和结束之间的所有语句必须存在于同一源文件中。

I suppose that is why my idea does not work? 我想这就是为什么我的想法行不通的原因?

Am I doing something wrong, or is there another solution? 我是在做错什么,还是有其他解决方案?

This workaround might suit. 此解决方法可能适合。 The only downside I have found so far is that the included files do not appear in the Project Manager. 到目前为止,我发现的唯一缺点是所包含的文件没有出现在项目管理器中。

  • Add the folder(s) containing the files to be included to the search path of every project. 将包含要包含的文件的文件夹添加到每个项目的搜索路径。
  • Create Include.pas, a normal .pas file, and include it in the normal way in every project. 创建一个Include.pas,一个普通的.pas文件,并以普通方式将其包含在每个项目中。
  • Add the files to be included in multiple projects to the uses clause of Include.pas. 将要包含在多个项目中的文件添加到Include.pas的uses子句中。 $IFDEFS can be used if required. 如果需要,可以使用$ IFDEFS。

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

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