注:other question的标题不同,导致无法识别为匹配的。
系统.类
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 Error] MyUnit.pas(85): E2037 Declaration of 'Notify' differs from previous declaration
在实现部分:
[dcc32 Error] MyUnit.pas(475): E2008 Incompatible types
问题
哪里错了?
最佳答案
不幸的是,Delphi 声明了 TCollectionNotification
两次:一个驻留在 System.Classes 中,另一个驻留在 System.Generics.Collections 中。
要解决此问题,请将 use 子句中的 System.Generics.Collections 移到 System.Classes 之前,或将其限定为 System.Classes.TCollectionNotification
)。
关于delphi - 无法覆盖 TCollection.Notify : Declaration of Notify differs from previous declaration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48345167/