-
Notifications
You must be signed in to change notification settings - Fork 2
/
MainUnit.pas
56 lines (48 loc) · 1.25 KB
/
MainUnit.pas
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
unit MainUnit;
interface
procedure Main;
implementation
uses
Knockoff.Observable;
type
TViewModel = class
strict private
fPersonName: Observable<string>;
public
constructor Create(const personName: string);
property PersonName: Observable<string> read fPersonName;
end;
constructor TViewModel.Create(const personName: string);
begin
fPersonName := Observable.Create(personName);
end;
procedure Main;
var
myViewModel: TViewModel;
sub: ISubscribable<string>;
begin
myViewModel := TViewModel.Create('John');
try
Writeln(myViewModel.PersonName());
sub := myViewModel.PersonName as ISubscribable<string>;
sub.Subscribe(
// myViewModel.PersonName.Subscribe(
procedure (const newValue: string)
begin
Writeln('old value: ' + newValue)
end, BeforeChange);
sub := myViewModel.PersonName as ISubscribable<string>;
sub.Subscribe(
// myViewModel.PersonName.Subscribe(
procedure (const newValue: string)
begin
Writeln('value changed to: ' + newValue)
end);
myViewModel.PersonName('Bob');
Writeln(myViewModel.PersonName());
finally
myViewModel.Free;
end;
ReportMemoryLeaksOnShutdown := True;
end;
end.