Skip to content

Commit ec73f22

Browse files
Added Include/Exclude filters to dispatchers
1 parent 2e4ea97 commit ec73f22

10 files changed

+191
-53
lines changed

demos/Fmx/Main.fmx

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ object Form2: TForm2
22
Left = 0
33
Top = 0
44
Caption = 'Form2'
5-
ClientHeight = 432
6-
ClientWidth = 923
5+
ClientHeight = 479
6+
ClientWidth = 935
77
FormFactor.Width = 320
88
FormFactor.Height = 480
99
FormFactor.Devices = [Desktop]
@@ -15,25 +15,17 @@ object Form2: TForm2
1515
Size.Width = 433.000000000000000000
1616
Size.Height = 297.000000000000000000
1717
Size.PlatformDefault = False
18-
inherited LogMemo: TMemo
19-
Viewport.Width = 381.000000000000000000
20-
Viewport.Height = 229.000000000000000000
21-
end
2218
end
2319
inline rx2: TFrame1
2420
Position.X = 472.000000000000000000
2521
Position.Y = 16.000000000000000000
2622
Size.Width = 431.000000000000000000
2723
Size.Height = 297.000000000000000000
2824
Size.PlatformDefault = False
29-
inherited LogMemo: TMemo
30-
Viewport.Width = 381.000000000000000000
31-
Viewport.Height = 229.000000000000000000
32-
end
3325
end
3426
object helloButton: TButton
3527
Position.X = 40.000000000000000000
36-
Position.Y = 328.000000000000000000
28+
Position.Y = 344.000000000000000000
3729
Size.Width = 137.000000000000000000
3830
Size.Height = 22.000000000000000000
3931
Size.PlatformDefault = False
@@ -43,7 +35,7 @@ object Form2: TForm2
4335
end
4436
object goodbyeButton: TButton
4537
Position.X = 216.000000000000000000
46-
Position.Y = 328.000000000000000000
38+
Position.Y = 344.000000000000000000
4739
Size.Width = 137.000000000000000000
4840
Size.Height = 22.000000000000000000
4941
Size.PlatformDefault = False
@@ -53,7 +45,7 @@ object Form2: TForm2
5345
end
5446
object thdSendButton: TButton
5547
Position.X = 40.000000000000000000
56-
Position.Y = 368.000000000000000000
48+
Position.Y = 384.000000000000000000
5749
Size.Width = 209.000000000000000000
5850
Size.Height = 22.000000000000000000
5951
Size.PlatformDefault = False
@@ -63,7 +55,7 @@ object Form2: TForm2
6355
end
6456
object Button1: TButton
6557
Position.X = 416.000000000000000000
66-
Position.Y = 328.000000000000000000
58+
Position.Y = 344.000000000000000000
6759
Size.Width = 177.000000000000000000
6860
Size.Height = 22.000000000000000000
6961
Size.PlatformDefault = False
@@ -74,8 +66,15 @@ object Form2: TForm2
7466
object chkAsync: TCheckBox
7567
IsChecked = True
7668
Position.X = 272.000000000000000000
77-
Position.Y = 371.000000000000000000
69+
Position.Y = 387.000000000000000000
7870
TabOrder = 6
7971
Text = 'Async'
8072
end
73+
object chkExclude: TCheckBox
74+
Position.X = 272.000000000000000000
75+
Position.Y = 312.000000000000000000
76+
TabOrder = 7
77+
Text = 'Exclude Goodbye'
78+
OnChange = chkExcludeChange
79+
end
8180
end

demos/Fmx/Main.pas

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ interface
55
uses
66
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
77
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
8-
VSoft.Messaging, FMX.Controls.Presentation, FMX.ScrollBox, FMX.Memo,
9-
MsgDemoFMXFrame, MsgDemoMessages, FMX.StdCtrls;
8+
VSoft.Messaging, FMX.Controls.Presentation, FMX.Memo,
9+
MsgDemoFMXFrame, FMX.StdCtrls;
1010

1111
type
1212
TForm2 = class(TForm)
@@ -17,11 +17,13 @@ TForm2 = class(TForm)
1717
thdSendButton: TButton;
1818
Button1: TButton;
1919
chkAsync: TCheckBox;
20+
chkExclude: TCheckBox;
2021
procedure FormCreate(Sender: TObject);
2122
procedure helloButtonClick(Sender: TObject);
2223
procedure goodbyeButtonClick(Sender: TObject);
2324
procedure thdSendButtonClick(Sender: TObject);
2425
procedure Button1Click(Sender: TObject);
26+
procedure chkExcludeChange(Sender: TObject);
2527
private
2628
{ Private declarations }
2729
FChannel : IMessageChannel;
@@ -34,6 +36,9 @@ TForm2 = class(TForm)
3436

3537
implementation
3638

39+
uses
40+
MsgDemoMessages;
41+
3742
{$R *.fmx}
3843

3944
procedure TForm2.Button1Click(Sender: TObject);
@@ -44,6 +49,14 @@ procedure TForm2.Button1Click(Sender: TObject);
4449
FChannel.Queue.SendMessage(msg);
4550
end;
4651

52+
procedure TForm2.chkExcludeChange(Sender: TObject);
53+
begin
54+
if chkExclude.IsChecked then
55+
rx1.SetExcludeFilter([DEMO_MSG_GOODBYE])
56+
else
57+
rx1.SetExcludeFilter([]);
58+
end;
59+
4760
procedure TForm2.FormCreate(Sender: TObject);
4861
begin
4962
FChannel := TMessageChannelFactory.CreateChannel;

demos/Fmx/MsgDemoFMXFrame.fmx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@ object Frame1: TFrame1
22
Size.Width = 431.000000000000000000
33
Size.Height = 292.000000000000000000
44
Size.PlatformDefault = False
5+
TabOrder = 0
56
object LogMemo: TMemo
67
Touch.InteractiveGestures = [Pan, LongTap, DoubleTap]
7-
DataDetectorTypes = []
88
Position.X = 32.000000000000000000
99
Position.Y = 24.000000000000000000
1010
Size.Width = 385.000000000000000000
1111
Size.Height = 233.000000000000000000
1212
Size.PlatformDefault = False
1313
TabOrder = 0
14-
Viewport.Width = 381.000000000000000000
15-
Viewport.Height = 229.000000000000000000
1614
end
1715
object ProgressBar1: TProgressBar
1816
Orientation = Horizontal

demos/Fmx/MsgDemoFMXFrame.pas

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ interface
55
uses
66
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
77
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
8-
FMX.Controls.Presentation, FMX.ScrollBox, FMX.Memo, VSoft.Messaging, MsgDemoMessages;
8+
FMX.Controls.Presentation, FMX.Memo, VSoft.Messaging, MsgDemoMessages, FMX.Layouts;
99

1010
type
1111
TFrame1 = class(TFrame)
@@ -21,6 +21,7 @@ TFrame1 = class(TFrame)
2121
public
2222
{ Public declarations }
2323
procedure Init(const channel : IMessageChannel);
24+
procedure SetExcludeFilter(const filter : TArray<Cardinal>);
2425
constructor Create(AOwner: TComponent); override;
2526
destructor Destroy;override;
2627
end;
@@ -70,4 +71,9 @@ procedure TFrame1.Progress(var msg: TProgressMessage);
7071
ProgressBar1.Value := msg.Progress;
7172
end;
7273

74+
procedure TFrame1.SetExcludeFilter(const filter: TArray<Cardinal>);
75+
begin
76+
FDispatcher.ExcludeFilter := filter;
77+
end;
78+
7379
end.

demos/Vcl/MsgDemoMainForm.dfm

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ object Form2: TForm2
5252
end
5353
object helloButton: TButton
5454
Left = 16
55-
Top = 248
55+
Top = 280
5656
Width = 105
5757
Height = 25
5858
Caption = 'Say Hello'
@@ -61,7 +61,7 @@ object Form2: TForm2
6161
end
6262
object goodbyeButton: TButton
6363
Left = 191
64-
Top = 248
64+
Top = 280
6565
Width = 106
6666
Height = 25
6767
Caption = 'Say GoodBye'
@@ -70,7 +70,7 @@ object Form2: TForm2
7070
end
7171
object thrdSendButton: TButton
7272
Left = 16
73-
Top = 288
73+
Top = 320
7474
Width = 156
7575
Height = 25
7676
Caption = 'PostMessage from Thread'
@@ -79,7 +79,7 @@ object Form2: TForm2
7979
end
8080
object sayHelloSyncButton: TButton
8181
Left = 328
82-
Top = 248
82+
Top = 280
8383
Width = 137
8484
Height = 25
8585
Caption = 'Say Hello Sync'
@@ -88,12 +88,21 @@ object Form2: TForm2
8888
end
8989
object chkAsync: TCheckBox
9090
Left = 191
91-
Top = 292
91+
Top = 324
9292
Width = 97
9393
Height = 17
9494
Caption = 'Async'
9595
Checked = True
9696
State = cbChecked
9797
TabOrder = 6
9898
end
99+
object chkExclude: TCheckBox
100+
Left = 191
101+
Top = 239
102+
Width = 129
103+
Height = 17
104+
Caption = 'Exclude Goodbye'
105+
TabOrder = 7
106+
OnClick = chkExcludeClick
107+
end
99108
end

demos/Vcl/MsgDemoMainForm.pas

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ TForm2 = class(TForm)
1616
thrdSendButton: TButton;
1717
sayHelloSyncButton: TButton;
1818
chkAsync: TCheckBox;
19+
chkExclude: TCheckBox;
1920
procedure FormCreate(Sender: TObject);
2021
procedure helloButtonClick(Sender: TObject);
2122
procedure goodbyeButtonClick(Sender: TObject);
2223
procedure thrdSendButtonClick(Sender: TObject);
2324
procedure sayHelloSyncButtonClick(Sender: TObject);
25+
procedure chkExcludeClick(Sender: TObject);
2426
private
2527
FChannel : IMessageChannel;
2628
public
@@ -37,6 +39,14 @@ implementation
3739
uses
3840
MsgDemoMessages;
3941

42+
procedure TForm2.chkExcludeClick(Sender: TObject);
43+
begin
44+
if chkExclude.Checked then
45+
rx1.SetExcludeFilter([DEMO_MSG_GOODBYE])
46+
else
47+
rx1.SetExcludeFilter([]);
48+
end;
49+
4050
procedure TForm2.FormCreate(Sender: TObject);
4151
begin
4252
FChannel := TMessageChannelFactory.CreateChannel;

demos/Vcl/MsgFrame.pas

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ TMsgRecieverFrame = class(TFrame)
2222
public
2323
{ Public declarations }
2424
procedure Init(const channel : IMessageChannel);
25+
procedure SetExcludeFilter(const filter : TArray<Cardinal>);
2526
constructor Create(AOwner: TComponent); override;
2627
destructor Destroy;override;
2728
end;
@@ -35,8 +36,9 @@ implementation
3536
constructor TMsgRecieverFrame.Create(AOwner: TComponent);
3637
begin
3738
inherited;
38-
FDispatcher := TMessageDispatcherFactory.CreateUIDispatcher; //note it's a UI message dispatcher, it will use Synchronize
39-
FDispatcher.Target := Self; //Dispatch the messages to this object.
39+
//either pass in the target for the messages, or set the Target Property.
40+
FDispatcher := TMessageDispatcherFactory.CreateUIDispatcher(self); //note it's a UI message dispatcher, it will use Synchronize
41+
// FDispatcher.Target := Self; //Dispatch the messages to this object.
4042

4143
end;
4244

@@ -69,4 +71,9 @@ procedure TMsgRecieverFrame.Progress(var msg: TProgressMessage);
6971

7072
end;
7173

74+
procedure TMsgRecieverFrame.SetExcludeFilter(const filter: TArray<Cardinal>);
75+
begin
76+
FDispatcher.ExcludeFilter := filter;
77+
end;
78+
7279
end.

0 commit comments

Comments
 (0)