-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDMessagingApp.dpr
47 lines (39 loc) · 990 Bytes
/
DMessagingApp.dpr
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
program DMessagingApp;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
DMessaging in 'Src\DMessaging.pas',
DMessaging.Channel in 'Src\DMessaging.Channel.pas';
const
MSG_NEW_USER = 'NewUser';
type
TUser = class
Firstname, Lastname: string;
public
constructor Create(const aFirstname, aLastname: string);
end;
constructor TUser.Create(const aFirstname, aLastname: string);
begin
Firstname := aFirstname;
Lastname := aLastname;
end;
begin
try
TMessaging.RegisterAnonymousSubscriber<TUser>(
procedure (const MessageID: string; Arg: TUser)
begin
if MessageID = MSG_NEW_USER then
Writeln('New user: ', Arg.Firstname, ' ', Arg.Lastname);
end
);
TMessaging.SendThenFree(
MSG_NEW_USER,
TUser.Create('Foo', 'Bar')
);
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
ReadLn;
end.