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 keypolicy (Sender: tobject; const item: string;
Action: tcollectionnotification );
Procedure valuenoworkflow (Sender: tobject; const item: integer;
Action: tcollectionnotification );
End;
VaR
Form1: tform1;
Implementation
{$ R *. DFM}
Procedure tform1.keypolicy (Sender: tobject; const item: string;
Action: tcollectionnotification );
Begin
Case action
Cnadded: showmessagefmt ('key _ add: % s', [item]);
Cnremoved: showmessagefmt ('key _ remove: % s', [item]);
Cnextracted: showmessagefmt ('key _ extract: % s', [item]);
End;
End;
Procedure tform1.valuenoworkflow (Sender: tobject; const item: integer;
Action: tcollectionnotification );
Begin
Case action
Cnadded: showmessagefmt ('value _ add: % d', [item]);
Cnremoved: showmessagefmt ('value _ remove: % d', [item]);
Cnextracted: showmessagefmt ('value _ extract: % d', [item]);
End;
End;
Procedure tform1.button1click (Sender: tobject );
VaR
Dictionary: tdictionary <string, integer>;
Begin
Dictionary: = tdictionary <string, integer>. Create ();
Dictionary. onkeypolicy: = keypolicy;
Dictionary. onvaluenoworkflow: = valuenoworkflow;
Dictionary. Add ('n1 ', 111); {key_add: N1; value_add: 111}
Dictionary. Add ('n2 ', 222); {key_add: N2; value_add: 222}
Dictionary. addorsetvalue ('n1 ', 123); {value_remove: 111; value_add: 123}
Dictionary. Remove ('n1 '); {key_remove: N1; value_remove: 111}
Dictionary. extractpair ('n2 '); {key_extract: N2; value_extract: 222}
Dictionary. onkeypolicy: = nil;
Dictionary. onvaluenovel: = nil;
Dictionary. Free;
End;
End.