Pau*_*aul 2 delphi tcollection
注意:其他问题的标题不同,这使其无法识别为匹配的标题.
System.Classes
TCollection = class(TPersistent)
protected
procedure Notify(Item: TCollectionItem; Action: TCollectionNotification); virtual;
end;
Run Code Online (Sandbox Code Playgroud)
MyUnit
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;
Run Code Online (Sandbox Code Playgroud)
Notify方法的签名是通过复制粘贴进行的,因此不会出现任何错误;
错误
在界面部分:
[dcc32错误] MyUnit.pas(85):E2037"通知"声明与之前的声明不同
在实施部分:
[dcc32错误] MyUnit.pas(475):E2008不兼容的类型
题
Wai错了?
Uwe*_*abe 10
不幸的是,Delphi声明了TCollectionNotification两次:一个驻留在System.Classes中,另一个驻留在System.Generics.Collections中.
要解决此问题,请在uses子句中的System.Classes之前移动System.Generics.Collections,或将其限定为).System.Classes.TCollectionNotification