每隔几周,我就会遇到这个问题:在 Delphi 项目中对使用单元执行 IDE 操作时,它会破坏.dpr
文件。
发生的情况是它重建了uses
列表,但位置错误。
我想知道要避免什么使用模式,所以我不会再遇到这个错误。
我在许多 Delphi 版本中都出现过这个错误。我知道它至少存在于 Delphi XE2(今天又发生了)、XE、2007、2006 和 7 中。
损坏的片段通常是这样的结构:
ususes
Forms,
..
LastUnitInUses in 'LastUnitInUses.pas';
R *.RES}
并且应该通过删除一个us
并添加一个来纠正{$
:
uses
Forms,
..
LastUnitInUses in 'LastUnitInUses.pas';
{R *.RES}
出错的示例文件:
program SysUtilsFormatTests;
{
Delphi DUnit Test Project
-------------------------
This project contains the DUnit test framework and the GUI/Console test runners.
Add "CONSOLE_TESTRUNNER" to the conditional defines entry in the project options
to use the console test runner. Otherwise the GUI test runner will be used by
default.
}
{$IFDEF CONSOLE_TESTRUNNER}
{$APPTYPE CONSOLE}
{$ENDIF}
ususes
Forms,
TestFramework,
GUITestRunner,
TextTestRunner,
SysUtilsFormatUnit in 'SysUtilsFormatUnit.pas';
R *.RES}
begin
Application.Initialize;
if IsConsole then
with TextTestRunner.RunRegisteredTests do
Free
else
GUITestRunner.RunRegisteredTests;
end.
更正.dpr
文件的示例:
program SysUtilsFormatTests;
{
Delphi DUnit Test Project
-------------------------
This project contains the DUnit test framework and the GUI/Console test runners.
Add "CONSOLE_TESTRUNNER" to the conditional defines entry in the project options
to use the console test runner. Otherwise the GUI test runner will be used by
default.
}
{$IFDEF CONSOLE_TESTRUNNER}
{$APPTYPE CONSOLE}
{$ENDIF}
uses
Forms,
TestFramework,
GUITestRunner,
TextTestRunner,
SysUtilsFormatUnit in 'SysUtilsFormatUnit.pas';
{$R *.RES}
begin
Application.Initialize;
if IsConsole then
with TextTestRunner.RunRegisteredTests do
Free
else
GUITestRunner.RunRegisteredTests;
end.