forked from CPsoftBE/BackupOfCromis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCromis.MVC.View.Frame.pas
138 lines (113 loc) · 3.11 KB
/
Cromis.MVC.View.Frame.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
unit Cromis.MVC.View.Frame;
interface
uses
Windows, SysUtils, Classes, Controls, Forms, Dialogs,
// cromis units
Cromis.MVC.View, Cromis.MVC.Common, Cromis.MVC.Model;
type
TMVCFrameView = class(TFrame, IMVCView)
private
FViewID: string;
FIsActive: Boolean;
FViewModel: IMVCModel;
FSessionData: ISessionData;
function GetSessionData: ISessionData;
procedure SetSessionData(const Value: ISessionData);
protected
procedure DoOnViewDeactivated(const Data: IMVCData); virtual;
procedure DoOnViewActivated(const Data: IMVCData); virtual;
public
property SessionData: ISessionData read GetSessionData write SetSessionData;
procedure UpdateView(const Section, ID: string; const Data: IMVCData); virtual;
procedure Deactivate(const Data: IMVCData = nil); virtual;
procedure Activate(const Data: IMVCData = nil); virtual;
procedure SetViewModel(const Model: IMVCModel);
procedure SetViewID(const Value: string);
function ViewModel: IMVCModel;
function IsActive: Boolean;
function ViewID: string;
procedure Cleanup;
end;
implementation
{$R *.dfm}
{ TMVCFrameView }
procedure TMVCFrameView.Activate(const Data: IMVCData);
var
I: Integer;
begin
for I := 0 to Parent.ControlCount - 1 do
begin
if Parent.Controls[I].ClassParent = TMVCFrameView then
begin
case Parent.Controls[I] <> Self of
True: Parent.Controls[I].Visible := False;
False: Parent.Controls[I].Visible := True;
end;
end;
end;
// now we are active
FIsActive := True;
// show frame
Self.Show;
// notify of activation
DoOnViewActivated(Data);
end;
procedure TMVCFrameView.Cleanup;
begin
FViewModel := nil;
end;
procedure TMVCFrameView.Deactivate(const Data: IMVCData);
begin
FIsActive := False;
Self.Hide;
// notify of deactivation
DoOnViewDeactivated(Data);
end;
procedure TMVCFrameView.DoOnViewActivated(const Data: IMVCData);
begin
Align := alClient;
end;
procedure TMVCFrameView.DoOnViewDeactivated(const Data: IMVCData);
begin
Align := alNone;
end;
function TMVCFrameView.GetSessionData: ISessionData;
begin
Result := FSessionData;
end;
function TMVCFrameView.IsActive: Boolean;
begin
Result := FIsActive
end;
function TMVCFrameView.ViewModel: IMVCModel;
begin
Result := FViewModel;
end;
procedure TMVCFrameView.SetSessionData(const Value: ISessionData);
begin
FSessionData := Value;
end;
procedure TMVCFrameView.SetViewID(const Value: string);
begin
FViewID := Value;
end;
procedure TMVCFrameView.SetViewModel(const Model: IMVCModel);
begin
FViewModel := Model;
end;
procedure TMVCFrameView.UpdateView(const Section, ID: string; const Data: IMVCData);
var
UpdateMethod: TUpdateViewProc;
begin
TMethod(UpdateMethod).Code := Self.MethodAddress(Format('UpdateView_%s', [Section]));
if TMethod(UpdateMethod).Code <> nil then
begin
TMethod(UpdateMethod).Data := Self;
UpdateMethod(ID, Data);
end;
end;
function TMVCFrameView.ViewID: string;
begin
Result := FViewID;
end;
end.