Cứ vài tuần, tôi gặp phải vấn đề này: khi thực hiện một hoạt động IDE trên các đơn vị sử dụng trong dự án Delphi, nó mangles các tập tin .
Điều gì xảy ra là nó xây dựng lại danh sách uses
nhưng bị sai vị trí.
Tôi tự hỏi mẫu sử dụng cần tránh vì vậy tôi sẽ không gặp phải lỗi này nữa.
Tôi đã xảy ra lỗi này trong nhiều phiên bản Delphi. Tôi biết nó tồn tại trong ít nhất Delphi XE2 (nó đã xảy ra đó một lần nữa ngày nay), XE, 2007, 2006 và 7.
Đoạn đọc sai thường được cấu trúc như thế này:
ususes
Forms,
..
LastUnitInUses in 'LastUnitInUses.pas';
R *.RES}
và cần được sửa chữa bởi loại bỏ một us
, và thêm một {$
: file
uses
Forms,
..
LastUnitInUses in 'LastUnitInUses.pas';
{R *.RES}
Ví dụ dù tiến hành sai:
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.
Ví dụ về điều chỉnh file:
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.
Tôi đã gặp sự cố tương tự khi tệp nguồn Delphi chứa kết hợp dòng kết thúc kiểu Unix và kiểu Windows. Bạn có thể kiểm tra xem '.dpr' của bạn chỉ chứa dòng kết thúc kiểu Windows không? Một cách dễ dàng để đảm bảo là mở tệp trong Notepad (phiên bản riêng của Windows): nó chỉ nhận ra các kết thúc dòng kiểu Windows, vì vậy nếu nó có vẻ khác so với hình thức của nó trong Delphi, có bạn đi. – hvd
Ngoài ra, không mở dpr trong tab trình soạn thảo nguồn __active__. Bạn có thể mở nó trên một tab khác, nhưng nếu nó được mở trong tab hoạt động, tôi đã thấy các vấn đề tương tự. –
Đó là một điều tốt. Tôi không chắc chắn nó đã được mở trong tab hoạt động hay không. –