unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Memo.Types,
FMX.Controls.Presentation, FMX.ScrollBox, FMX.Memo,
FMX.Presentation.Messages, FMX.StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
FMessageSender: TMessageSender;
public
procedure DefaultHandler(var Message); override;
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.Button1Click(Sender: TObject);
begin
FMessageSender.SendMessage(100, '我是通过消息发送过来的信息'); // 命令ID & 发送数据值
end;
procedure TForm1.DefaultHandler(var Message);
begin
inherited;
ShowMessage(TDispatchMessage(Message).MsgID.ToString()); // 收到的命令ID
ShowMessage(TDispatchMessageWithValue<String>(Message).Value); // 收到的数据值
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FMessageSender := TMessageSender.Create();
FMessageSender.Receiver := Self;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FMessageSender.DisposeOf();
end;
end.