问题描述
为了维护其项目,Delphi有时从DPR文件(项目源)添加或删除内容。我非常喜欢在DPR中格式化我的东西,就像它是一个普通的单元,例如将已用框架引用和项目源文件组合在一起。我复制它,并且可以在发生这种情况时返回,但是经常出现的时候,我会注意到DPR已将所有的源文件引用捣毁成一个块。
谢谢
我对我的大部分项目做的是拥有这两个文件:
- MyProgram.dpr
- MyProgramUnit.pas
MyProgramUnit
有一个公共方法 Main
,其中包含.dpr中的所有逻辑(包括任何条件定义)
MyProgram
只需调用 Main
。
编辑1:
您可以将用户列表放在 MyProgramUnit.pas
,但它们不会自动成为您项目的一部分。
这可能或可能不是一个问题,这取决于您是否希望Delphi在搜索路径中查找单位,或者将文件添加到项目中使其可见。
你可以做的是在 MyProgramUnit.pas
中记录用户列表,并按原因分组。这是我通常在大多数单位做的,不仅在主要单位。
编辑2:
不要去 {$ I MyIncludeFile.inc}
方式。
Delphi - 特别是IDE - 是坏的包含文件。代码完成等在不规则的地方失败。
过去我一直很重视包含文件;不再这样了我甚至停止使用它们进行定义,并从 {$ IFDEF define} ... {$ ENDIF}
向 {$ IF Constant1> = Constant2} ... {$ IFEND}
。
To maintain its project, Delphi sometimes adds or removes stuff from the DPR file (project source). I quite like to format my stuff in the DPR as if it is an ordinary unit, for example to group together the 'used' frame references and project source files. I make copies of it and can go back when this happens but every so often, I'll notice that the DPR has had all its source file references smashed into a single block.
Anyone else suffer from this? Is there any way of preventing this from happening (other than a read-only file).Thanks
What I do for most of my projects is to have these 2 files:
- MyProgram.dpr
- MyProgramUnit.pas
MyProgramUnit
has a public method Main
that contains all the logic from the .dpr (including any conditional defines)
MyProgram
just calls Main
.
Edit 1:
You can put uses lists in MyProgramUnit.pas
, but they don't automatically become part of your project.That might or might not be an issue, it depends if you like having Delphi finding units in a search path, or add files to your project to make them visible.
What you can do, is to document the uses-lists in MyProgramUnit.pas
and group them by cause. This is what I normally do in most units anyway, not only in the main unit.
Edit 2:
Don't go the {$I MyIncludeFile.inc}
way.
Delphi - especially the IDE - is bad with include files. Code Completion, etc, fail at irregular places.
I've been heavy on include files in the past; not so any more. I even stopped using them for defines, and moved from {$IFDEF define} ... {$ENDIF}
towards {$IF Constant1 >= Constant2} ... {$IFEND}
.
这篇关于如何防止Delphi意外修改DPR(项目源)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!