-
Notifications
You must be signed in to change notification settings - Fork 1
/
Unit1.cpp
67 lines (65 loc) · 2.7 KB
/
Unit1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//---------------------------------------------------------------------------
#include <fmx.h>
#pragma hdrstop
#include <System.TypInfo.hpp>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
// map subscriptions to handlers
m_Registrar.Subscribe<Event>(OnEvent);
m_Registrar.Subscribe<OnChange<int>>(OnChangeInt);
m_Registrar.Subscribe<OnChange<String>>(OnChangeString);
}
//---------------------------------------------------------------------------
// send messages/events
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1KeyDown(TObject *Sender, WORD &Key, System::WideChar &KeyChar, TShiftState Shift)
{
::Messaging::Bus::Publish(OnChange<String>("Edit1.Text.Changed",Edit1->Text));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NumberBox1Change(TObject *Sender)
{
::Messaging::Bus::Publish(OnChange<int>("NumberBox1.Value.Changed", NumberBox1->Value));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
::Messaging::Bus::Publish(Event("LoadData"));
::Messaging::Bus::Publish(OnChange<int>("Button1.Click",73));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CheckBox1Change(TObject *Sender)
{
::Messaging::Bus::Publish(Event("RefreshList"));
::Messaging::Bus::Publish(OnChange<int>("CheckBox1.IsChecked.Changed", CheckBox1->IsChecked ? 1 : 0));
}
//---------------------------------------------------------------------------
// Handlers
//---------------------------------------------------------------------------
void __fastcall TForm1::OnEvent(const Event& message)
{
Form1->Memo1->Lines->Add("Event: " + message.Id);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OnChangeInt(const OnChange<int>& message)
{
Form1->Memo1->Lines->Add(message.Id + "=" + IntToStr(message.Value));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OnChangeString(const OnChange<String>& message)
{
auto msg = message;
Form1->Memo1->Lines->Add(msg.Id + "=" + msg.Value);
}
//---------------------------------------------------------------------------