Delphi XE2中的重复构造函数警告

7

我有以下的.dpr文件

program TPWDDBManager;
{

  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
  DUnitTestRunner,
  TestuTPWDDBManager in 'TestuTPWDDBManager.pas';

{$R *.RES}

begin
  DUnitTestRunner.RunRegisteredTests;
end.

并且下一个单元:
unit TestuTPWDDBManager;
{

  Delphi DUnit Test Case
  ----------------------
  This unit contains a skeleton test case class generated by the Test Case Wizard.
  Modify the generated code to correctly setup and call the methods from the unit
  being tested.

}

interface

uses TestFramework;

type
  // Test methods for class TPWDDBManager

  TestTPWDDBManager = class(TTestCase)
  strict private
  public
    procedure SetUp; override;
    procedure TearDown; override;
  published
    procedure TestUpdateVersion;
    procedure TestGetPWD;
    procedure TestChangePWD;
    procedure TestReset;
    procedure TestIsReset;

  end;

  Idlg = interface(IInvokable)
    ['{E369D075-E3CA-4BB3-896C-0D623DE5798F}']

  end;

implementation

uses SysUtils,Delphi.Mocks;

procedure TestTPWDDBManager.SetUp;
var
  FMessageDLG : TMock<IDlg>;
begin
end;

procedure TestTPWDDBManager.TearDown;
begin
end;

procedure TestTPWDDBManager.TestGetPWD;
begin
  // TODO: Validate method results
end;

procedure TestTPWDDBManager.TestIsReset;
begin
end;

procedure TestTPWDDBManager.TestChangePWD;
begin
end;

procedure TestTPWDDBManager.TestReset;
begin
end;

procedure TestTPWDDBManager.TestUpdateVersion;
begin

end;

initialization
  // Register any test cases with the test runner
  RegisterTest(TestTPWDDBManager.Suite);
end.

当我进行编译时,我得到了几个警告,如下所示:
[DCC Warning] W1029:拥有相同参数的重复构造函数“TExpectation.CreateAfter”将无法从C++中访问 [DCC Warning] W1029:拥有相同参数的重复构造函数“TExpectation.CreateAfterWhen”将无法从C++中访问 [DCC Warning] W1029:拥有相同参数的重复构造函数“TExpectation.CreateAtLeastOnce”将无法从C++中访问
但是,如果我删除FMessageDLG : TMock<IDlg>;这一行,则会消除警告。请问如何解决这个问题?

4
在Delphi项目中,Delphi Mocks和C++兼容编译器标志是相互不兼容的。只需在编译器设置中关闭C++兼容选项即可。请记住,Delphi用于许多目的。这个警告在某些使用场景下确实有作用,但对大多数Delphi用户的日常工作没有影响。您可以禁用此警告。将“{$WARN UPLICATE_CTOR_DTOR OFF}”添加到您的单元中即可。 - Warren P
1
@WarrenP 这应该是一个答案。 - jpfollenius
1
@WarrenP:我猜UPLICATE实际上是DUPLICATE,对吗?还有一个问题:将其放在我的单元上并没有解决问题,我必须将其放在项目的单元上,然后警告才消失了,为什么会这样? - Felipe Morais
项目范围首先要确定。单元范围不会影响其他单元,因此有所不同。 - Warren P
似乎无法迁移或编辑旧评论。无论如何,还是发布为答案,以防更多人看到它。 - Warren P
2个回答

7

Delphi项目中的“Mocks”和C++兼容性编译器标志是相互矛盾的。只需在编译器设置中关闭C++兼容性选项即可。请记住,Delphi用于多种目的。这个警告在某些使用场景中有用,但在大多数Delphi用户的日常工作中并不需要。您可以禁用此警告。

{$WARN DUPLICATE_CTOR_DTOR OFF} 

根据需要添加到PROJECT(.dpr)范围或单元范围,以进行修复。


嗨。该指令会自动从DPK文件中被IDE移除。有什么解决办法吗? - Gabriel

4

这个警告的意思就是字面上的意思。如果你对C++兼容性不感兴趣,那么可以简单地禁用这个警告。否则,需要更改TExpectation的定义,使其具有按参数列表而不是仅按名称区分的构造函数。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接