Unit unit1;
Interface
Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, stdctrls, generics. collections;
Type
Tform1 = Class (tform)
Button1: tbutton;
Procedure button1click (Sender: tobject );
Private
Procedure mylistpolicy (Sender: tobject; const item: string;
Action: tcollectionnotification );
End;
VaR
Form1: tform1;
Implementation
{$ R *. DFM}
{Prepare the event process for list. onnotify call}
Procedure tform1.mylistpolicy (Sender: tobject; const item: string;
Action: tcollectionnotification );
Begin
Case action
Cnadded: showmessagefmt ('add: % s', [item]);
Cnremoved: showmessagefmt ('remove: % s', [item]);
Cnextracted: showmessagefmt ('extract: % s', [item]);
End;
End;
Procedure tform1.button1click (Sender: tobject );
VaR
List: tlist <string>;
Begin
List: = tlist <string>. Create ();
List. onnotify: = mylistpolicy; {event association process}
List. addrange (['A', 'B', 'C']); {Add: A | Add: B | Add: c}
List. Delete (0); {remove:}
List. Remove ('B'); {remove: B}
List. Extract ('C'); {extract: c}
List. onnotify: = nil;
List. Free;
End;
End.