博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
详测 Generics Collections TDictionary(4): OnKeyNotify、OnValueNotify
阅读量:7250 次
发布时间:2019-06-29

本文共 1812 字,大约阅读时间需要 6 分钟。

  hot3.png

unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, StdCtrls, Generics.Collections;type  TForm1 = class(TForm)    Button1: TButton;    procedure Button1Click(Sender: TObject);  private    procedure KeyNotify(Sender: TObject; const Item: string;      Action: TCollectionNotification);    procedure ValueNotify(Sender: TObject; const Item: Integer;      Action: TCollectionNotification);  end;var  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.KeyNotify(Sender: TObject; const Item: string;  Action: TCollectionNotification);begin  case Action of    cnAdded     : ShowMessageFmt('Key_Add: %s', [Item]);    cnRemoved   : ShowMessageFmt('Key_Remove: %s', [Item]);    cnExtracted : ShowMessageFmt('Key_Extract: %s', [Item]);  end;end;procedure TForm1.ValueNotify(Sender: TObject; const Item: Integer;  Action: TCollectionNotification);begin  case Action of    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
;begin Dictionary := TDictionary
.Create(); Dictionary.OnKeyNotify := KeyNotify; Dictionary.OnValueNotify := ValueNotify; 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.OnKeyNotify := nil; Dictionary.OnValueNotify := nil; Dictionary.Free;end;end.

转载于:https://my.oschina.net/hermer/blog/319294

你可能感兴趣的文章
一套代码称霸5大端口,移动金融应用还能这样开发?
查看>>
MIT开发Polaris,使网页载入加快34%
查看>>
微软对macOS和Linux开放量子开发工具集
查看>>
一份关于Angular的倡议清单
查看>>
没有估算,你仍然可以用这些决策策略
查看>>
通过调研开源基准测试集,解读大数据的应用现状和开源未来
查看>>
译文-调整G1收集器窍门
查看>>
时序数据库InfluxDB 2.0 alpha 发布:主推新的Flux查询语言,TICK栈将成为整体
查看>>
开源是项“全民工程”,揭秘开源团队的管理运作
查看>>
基于Gitflow分支模型自动化Java项目工作流
查看>>
ES6学习之一
查看>>
专访何红辉:谈谈Android源码中的设计模式
查看>>
超2亿中国用户简历曝光!MongoDB又一重大安全事故
查看>>
网易云信周梁伟专访:亿级架构IM平台的技术难点解析
查看>>
独家揭秘腾讯千亿级参数分布式机器学习系统无量
查看>>
Dubbo Mesh在闲鱼生产环境的落地实践
查看>>
微软Build 2017第二天:跨平台跨硬件开发体验
查看>>
精益项目管理的可行性分析
查看>>
Bitbucket Pipelines在Atlassian的Bitbucket云上提供持续交付功能
查看>>
举重若轻的人人车移动端数据平台
查看>>