zoukankan      html  css  js  c++  java
  • 详测 Generics Collections TList (10): OnNotify 事件

    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 MyListNotify(Sender: TObject; const Item: string;
          Action: TCollectionNotification);
      end;
     
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    {准备给 List.OnNotify 调用的事件过程}
    procedure TForm1.MyListNotify(Sender: TObject; const Item: string; 
      Action: TCollectionNotification);
    begin
      case Action of
        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 := MyListNotify; {关联事件过程}
    
      List.AddRange(['A', 'B', 'C']); {Add: A | Add: B | Add: C }
    
      List.Delete(0);    {Remove: A}
      List.Remove('B');  {Remove: B}
      List.Extract('C'); {Extract: C}
    
      List.OnNotify := nil;    
      List.Free;
    end;
    
    end.
    
  • 相关阅读:
    BufferedOutPutStream 字节缓冲输出流 BufferedIntPutSream 字节缓冲输入流
    Properpies
    jdk9的新特性
    try catch finally处理流的异常
    续写和换行
    write写入
    flush close
    Postman功能详解
    HyLoad压测的使用
    找出Window/Linux下 占用端口的进程
  • 原文地址:https://www.cnblogs.com/del/p/1580729.html
Copyright © 2011-2022 走看看