unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Presentation.Messages,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  FMX.Controls.Presentation, FMX.StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    FMessageSender: TMessageSender;
  public
    { Public declarations }
    procedure DefaultHandler(var Message); override;
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.Button1Click(Sender: TObject);
begin
  FMessageSender.SendMessage(10, 'aaa');
end;

procedure TForm1.DefaultHandler(var Message);
begin
  inherited;
  ShowMessage(TDispatchMessage(Message).MsgID.ToString());
  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.