zoukankan      html  css  js  c++  java
  • 消息分发

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
      TMsgRecord = record
        MsgID1: Integer;
        MsgID2: Integer;
        MsgName: string[15];
        MsgDesc: string[27];
      end;
    
      TMsgHandleClass = class
      private
        procedure SM_Message1(var MsgRec: TMsgRecord); message 2000;
        procedure SM_Message2(var MsgRec: TMsgRecord); message 2001;
        procedure SM_Message3(var MsgRec: TMsgRecord); message 2002;
      public
        procedure DefaultHandler(var Message); override;
      end;
    
    
    var
      Form1: TForm1;
      MsgObject: TMsgHandleClass;
    
    implementation
    
    {$R *.dfm}
    
    { TMsgHandleClass }
    
    procedure TMsgHandleClass.DefaultHandler(var Message);
    begin
      inherited;
      ShowMessage('DefaultHandler: ');
    end;
    
    procedure TMsgHandleClass.SM_Message1(var MsgRec: TMsgRecord);
    begin
      ShowMessage('2000');
    end;
    
    procedure TMsgHandleClass.SM_Message2(var MsgRec: TMsgRecord);
    begin
      ShowMessage('2001');
    end;
    
    procedure TMsgHandleClass.SM_Message3(var MsgRec: TMsgRecord);
    begin
      ShowMessage('2002');
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      MyMsg: TMsgRecord;
    begin
      FillChar(MyMsg, SizeOf(TMsgRecord), 0);
      MyMsg.MsgID1 := 2001;
      MyMsg.MsgID2 := 2000;
      MyMsg.MsgName := '2000消息';
      MyMsg.MsgDesc := '这是消息号为2000的消息';
      MsgObject.Dispatch(MyMsg);
    end;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      MsgObject := TMsgHandleClass.Create;
    end;
    
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
      MsgObject.Free;
      MsgObject := nil;
    end;
    
    end.
    

      

  • 相关阅读:
    struts2接收参数的几种形式
    oracle merge into函数中插入clob字段
    程序员能力矩阵
    spring mvc工作原理
    struts2核心和工作原理
    mysql主从复制(windows下)
    mysql主从复制(linux下)
    spring 注解事务
    异常错误集锦
    Redis 作为缓存服务器的配置
  • 原文地址:https://www.cnblogs.com/devinblog/p/5523322.html
Copyright © 2011-2022 走看看