簡體   English   中英

不要做什么來阻止Delphi在.DPR中修改使用列表和{$ *。RES}

[英]What to NOT do to prevent Delphi from mangling the uses list and {$*.RES} in a .DPR

每隔幾周,我就會碰到這一點:當在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.

我知道唯一可行的是讓IDE讓你管理.dpr文件。

  • 不要添加評論。
  • 不要使用$ IFDEF之類的條件。
  • 請勿修改.dpr文件中的代碼。

如果您執行上述任何操作,請期待IDE退回。

就個人而言,我做了所有這些並在提交時反擊。 我使用我的VCS來防御偽造的IDE更改。 這不是理想的,但它是最好的選擇。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM