delphi - 无法覆盖 TCollection.Notify : Declaration of Notify differs from previous declaration

标签 delphi tcollection

注: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/

相关文章:

delphi - 使用泛型和嵌套记录助手进行继承

delphi - KOL - 将 PStream 加载到 TImage

delphi - 由于 '%CLASSGROUP TPersistent' ,为什么工具选项板中可用于数据模块的组件比可用于表单的组件少?

c++ - 递归读取 TCollection

delphi - 创建具有命名子组件的组件?

delphi - Delphi 中的持久多态列表

delphi - XE4 iOS应用程序不会部署到设备

ios - Delphi iOS TMemo 滚动与平移