首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在spring4d中使用IMultiCastEvent?

如何在spring4d中使用IMultiCastEvent?
EN

Stack Overflow用户
提问于 2012-02-05 23:17:03
回答 1查看 503关注 0票数 1

我正在尝试使用spring4d的集合部分。但我不能订阅集合变更事件。在以下位置获取错误: DCC error: E2008不兼容的类型:

代码语言:javascript
复制
var
  TestList: TObjectList<TObject>;
begin
  ... List initialization code ...

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

TObjectList的OnNotify属性声明为:

property OnNotify: ICollectionNotifyDelegate<T>,其中

代码语言:javascript
复制
ICollectionNotifyDelegate<T> = interface(IMulticastEvent<Generics.Collections.TCollectionNotifyEvent<T>>)
end;

即OnNotify.Add方法需要一个Generics.Collections.TCollectionNotifyEvent,它声明为:

代码语言:javascript
复制
TCollectionNotifyEvent<T> = procedure(Sender: TObject; const Item: T; 
    Action: TCollectionNotification) of object;

我的事件处理程序声明为:

代码语言:javascript
复制
procedure TTestClass.TestHandler(Sender: TObject; const Item: TObject; Action: TCollectionNotification);
begin

end;

我很困惑%)请帮帮忙)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-02-06 00:17:37

这是由不同单位中的相同类型定义引起的:

Classes.pas:

TCollectionNotification = (cnAdded, cnExtracting, cnDeleting);

Generics.Collections.pas

TCollectionNotification = (cnAdded, cnRemoved, cnExtracted);

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

TCollectionNotification = Generics.Collections.TCollectionNotification;

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

附注:

建议使用对接版本的IList<T>

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9150361

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档