详测 Generics Collections TQueue (3): OnNotify、Extract
生活随笔
收集整理的這篇文章主要介紹了
详测 Generics Collections TQueue (3): OnNotify、Extract
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
為什么80%的碼農(nóng)都做不了架構(gòu)師?>>> ??
unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls, Generics.Collections;typeTForm1 = class(TForm)Button1: TButton;procedure Button1Click(Sender: TObject);privateprocedure MyQueueNotify(Sender: TObject; const Item: Integer;Action: TCollectionNotification);end;varForm1: TForm1;implementation{$R *.dfm}//uses Generics.Collections;{準(zhǔn)備給 TQueue.OnNotify 調(diào)用的事件過程} procedure TForm1.MyQueueNotify(Sender: TObject; const Item: Integer;Action: TCollectionNotification); begincase Action ofcnAdded : ShowMessageFmt('Add: %d', [Item]);cnRemoved : ShowMessageFmt('Remove: %d', [Item]);cnExtracted : ShowMessageFmt('Extract: %d', [Item]);end; end;procedure TForm1.Button1Click(Sender: TObject); varQueue: TQueue<Integer>; beginQueue := TQueue<Integer>.Create();Queue.OnNotify := MyQueueNotify;Queue.Enqueue(11); {Add: 11}Queue.Enqueue(22); {Add: 22}Queue.Enqueue(33); {Add: 33}Queue.Dequeue; {Remove: 11}// Extract 和 Dequeue 功能一致, 區(qū)別只是在驅(qū)動 OnNotify 事件時傳遞的參數(shù)有區(qū)別, 沒多大意義Queue.Extract; {Extract: 22}//Queue.OnNotify := nil;Queue.Free; {Remove: 33} end;end.轉(zhuǎn)載于:https://my.oschina.net/hermer/blog/319810
總結(jié)
以上是生活随笔為你收集整理的详测 Generics Collections TQueue (3): OnNotify、Extract的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 30多年程序员生涯经验总结(成功源自于失
- 下一篇: 学习 TTreeView [7] - I