I want to use the OnNotify event of a generic TList. Assigning a procedure to OnNotify yields the error message:
E2010 Incompatible types: 'System.Generics.Collections.TCollectionNotification' and 'System.Classes.TCollectionNotification'
I am declaring a class and in it a generic TList is used as follows:
TEditor_Table = class (TObject)
public
FEditors: TList<TGradient_Editor>; // List containing the editors
This is not the neatest way of doing it but I need this for a test. The list is instantiated in the constructor:
constructor TEditor_Table.Create (Owner: TFMXObject);
begin
inherited Create;
FEditors := TList<TGradient_Editor>.Create;
FOwner := Owner;
end; // Create //
Next in the main form a function is declared
procedure do_editor_change (Sender: TObject; const Item: TGradient_Editor; Action: TCollectionNotification);
and the TColor_Editor class is instantiated as follows:
FColor_Editor := TEditor_Table.Create (List_Gradients);
FColor_Editor.FEditors.OnNotify := do_editor_change;
^
error occurs here----------------------------------+
I do not understand the message at all and I am at a los why the compiler seems to confuse the two units: 'System.Generics.Collections.TCollectionNotification' and 'System.Classes.TCollectionNotification'. What am I doing wrong?
The problem is that the RTL defines two different versions of TCollectionNotification. One in System.Classes and one in Generics.Collections.
You are using TList<T> from Generics.Collections and so need the TCollectionNotification from Generics.Collections. But in your code TCollectionNotification is the version declared in System.Classes. That's because, at the point where you write TCollectionNotification, System.Classes was used after Generics.Collections.
Solutions are:
Generics.Collections appears after System.Classes. This is good practice no matter what. Or,Generics.Collections.TCollectionNotification.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With