码迷,mamicode.com
首页 > 其他好文 > 详细

消息分发

时间:2016-05-24 15:17:41      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:

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.

  

消息分发

标签:

原文地址:http://www.cnblogs.com/devinblog/p/5523322.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!