1

spring4dのコレクション部分の使用を開始しようとしています。ただし、コレクション変更イベントをサブスクライブできません。エラーを取得します:[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;

私は混乱しています%)助けてください)

4

1 に答える 1

5

これは、異なるユニットでの同じ型定義が原因でした:

Classes.pas:

TCollectionNotification = (cnAdded, cnExtracting, cnDeleting);

Generics.Collections.pas

TCollectionNotification = (cnAdded, cnRemoved, cnExtracted);

実際、Spring.Collections は型エイリアスを使用して使用を簡素化します。

TCollectionNotification = Generics.Collections.TCollectionNotification;

uses リスト句Spring.Collectionsの後に追加できます。Classes

PS

インターフェース化されたバージョンを使用することをお勧めしますIList<T>

于 2012-02-05T16:17:37.257 に答える