2

注意:其他问题的标题不同,这会阻止它识别为匹配的问题。

系统类

TCollection = class(TPersistent)
protected
  procedure Notify(Item: TCollectionItem; Action: TCollectionNotification); virtual;
end;

我的单位

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes,
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,
  Vcl.ExtCtrls, DB, System.Generics.Collections;

TTextDisplayLineInfos = class(TCollection)
protected
  procedure Notify(Item: TCollectionItem; Action: TCollectionNotification); override; //Here "[dcc32 Error] MyUnit.pas(85): E2037 Declaration of 'Notify' differs from previous declaration"
end;

implementation

procedure TTextDisplayLineInfos.Notify(Item: TCollectionItem;
  Action: TCollectionNotification);
begin
  inherited; //Here "[dcc32 Error] MyUnit.pas(475): E2008 Incompatible types"
  //..............
end;

Notify 方法的签名已经被复制粘贴了,所以不会有任何错误;

错误

在界面部分:

[dcc32 错误] MyUnit.pas(85):“通知”的 E2037 声明与之前的声明不同

在实施部分:

[dcc32 错误] MyUnit.pas(475): E2008 不兼容的类型

问题

怀有错吗?

4

1 回答 1

10

不幸的是,Delphi 声明TCollectionNotification了两次:一个位于System.Classes中,另一个位于System.Generics.Collections中。

要解决此问题,请将System.Generics.Collections移到您的 uses 子句中的System.Classes之前,或将其限定为System.Classes.TCollectionNotification)。

于 2018-01-19T16:47:59.323 回答