无法覆盖 TCollection.Notify:通知声明与之前的声明不同
Cannot override TCollection.Notify: Declaration of Notify differs from previous declaration
注意: 的标题不同,因此无法识别为匹配的标题。
System.Classes
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方法的签名已经被copy-paste拿走了,所以不会有任何错误;
错误
在界面部分:
[dcc32 Error] MyUnit.pas(85): E2037 Declaration of 'Notify' differs from previous declaration
在实施部分:
[dcc32 Error] MyUnit.pas(475): E2008 Incompatible types
问题
Whai错了?
不幸的是,Delphi 声明了两次 TCollectionNotification
:一次位于 System.Classes,另一次位于 System.Generics.Collections.
要解决此问题,请在您的 uses 子句中将 System.Generics.Collections 移到 System.Classes 之前,或对其进行限定如 System.Classes.TCollectionNotification
).
注意:
System.Classes
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方法的签名已经被copy-paste拿走了,所以不会有任何错误;
错误
在界面部分:
[dcc32 Error] MyUnit.pas(85): E2037 Declaration of 'Notify' differs from previous declaration
在实施部分:
[dcc32 Error] MyUnit.pas(475): E2008 Incompatible types
问题
Whai错了?
不幸的是,Delphi 声明了两次 TCollectionNotification
:一次位于 System.Classes,另一次位于 System.Generics.Collections.
要解决此问题,请在您的 uses 子句中将 System.Generics.Collections 移到 System.Classes 之前,或对其进行限定如 System.Classes.TCollectionNotification
).