本文整理自网络,侵删。
unit Unit1;
interface
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type TForm1 = class(TForm) Memo1: TMemo; Button1: TButton; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm}
uses Generics.Collections; {Delphi 2009 新增的泛型容器单元}var Dictionary: TDictionary<string,string>;//www.delphitop.com
procedure TForm1.Button1Click(Sender: TObject);varkey:string;pair: TPair<string,string>;begin
//自动去重复Dictionary.AddOrSetValue('key1', 'value1');Dictionary.AddOrSetValue('key1', 'value2');
{遍历看看}{ for pair in Dictionary.Keys do begin Memo1.Lines.Add(Dictionary[pair.Key]); //得到得结果都是不重复得 end; }
for key in Dictionary.Keys do begin Memo1.Lines.Add(key); //得到得结果都是不重复得 end;
end;
procedure TForm1.FormCreate(Sender: TObject);beginDictionary := TDictionary<string,string>.Create;
end;
end.
相关阅读 >>
Delphi tms web core messagedlg对话框 yes no
Delphi编写的android程序获取root权限实现(2015.4.15更新,支持android 4.4)
更多相关阅读请进入《Delphi》频道 >>