Delphi 如何使用spring4d的IMMulticastEvent?

Delphi 如何使用spring4d的IMMulticastEvent?,delphi,spring4d,Delphi,Spring4d,我正在尝试开始使用spring4d的集合部分。但我无法订阅收藏更改事件。获取错误:[DCC错误]:E2008不兼容类型位于: var TestList: TObjectList<TObject>; begin ... List initialization code ... TestList.OnNotify.Add(TestHandler); <--- Error here end 我很困惑(请帮助)这是由不同单元中的相同类型定义造成的: class.

我正在尝试开始使用spring4d的集合部分。但我无法订阅收藏更改事件。获取错误:[DCC错误]:E2008不兼容类型位于:

var
  TestList: TObjectList<TObject>;
begin
  ... List initialization code ...

  TestList.OnNotify.Add(TestHandler);     <--- Error here
end

我很困惑(请帮助)

这是由不同单元中的相同类型定义造成的:

class.pas:

TCollectionNotification=(cnAdded、cnExtracting、cnDeleting)

泛型.Collections.pas

TCollectionNotification=(cnAdded、cnRemoved、cnExtracted)

实际上,Spring.Collections使用类型别名来简化使用:

TCollectionNotification=Generics.Collections.TCollectionNotification

您可以在uses list子句中的
Classes
之后添加
Spring.Collections

附言


建议使用接口版本
IList

这是由于不同单元中的相同类型定义造成的:

class.pas:

TCollectionNotification=(cnAdded、cnExtracting、cnDeleting)

泛型.Collections.pas

TCollectionNotification=(cnAdded、cnRemoved、cnExtracted)

实际上,Spring.Collections使用类型别名来简化使用:

TCollectionNotification=Generics.Collections.TCollectionNotification

您可以在uses list子句中的
Classes
之后添加
Spring.Collections

附言

建议使用接口版本
IList

ICollectionNotifyDelegate<T> = interface(IMulticastEvent<Generics.Collections.TCollectionNotifyEvent<T>>)
end;
TCollectionNotifyEvent<T> = procedure(Sender: TObject; const Item: T; 
    Action: TCollectionNotification) of object;
procedure TTestClass.TestHandler(Sender: TObject; const Item: TObject; Action: TCollectionNotification);
begin

end;