[英]How to use a IMultiCastEvent from the spring4d?
我嘗試開始使用spring4d的collections部分。 但是我不能訂閱集合更改事件。 在以下位置獲取錯誤:[DCC錯誤]:E2008不兼容的類型:
var
TestList: TObjectList<TObject>;
begin
... List initialization code ...
TestList.OnNotify.Add(TestHandler); <--- Error here
end
TObjectList的OnNotify屬性聲明為:
property OnNotify: ICollectionNotifyDelegate<T>
,其中
ICollectionNotifyDelegate<T> = interface(IMulticastEvent<Generics.Collections.TCollectionNotifyEvent<T>>)
end;
即OnNotify.Add方法需要一個Generics.Collections.TCollectionNotifyEvent,它聲明為:
TCollectionNotifyEvent<T> = procedure(Sender: TObject; const Item: T;
Action: TCollectionNotification) of object;
我的事件處理程序聲明為:
procedure TTestClass.TestHandler(Sender: TObject; const Item: TObject; Action: TCollectionNotification);
begin
end;
我很困惑%)請幫助)
這是由不同單位中的相同類型定義引起的:
Classs.pas:
TCollectionNotification = (cnAdded, cnExtracting, cnDeleting);
Generics.Collections.pas
TCollectionNotification = (cnAdded, cnRemoved, cnExtracted);
實際上,Spring.Collections使用類型別名來簡化用法:
TCollectionNotification = Generics.Collections.TCollectionNotification;
您可以在“使用”列表子句中的“ Classes
之后添加Spring.Collections
。
PS
建議使用接口版本IList<T>
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.