每隔几周,我都会遇到这种情况:在 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.