1 | unit OsSystem;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Forms, Generics.Collections;
|
---|
7 |
|
---|
8 | type
|
---|
9 | TSystem = class;
|
---|
10 | TFormTask = class;
|
---|
11 | TFormTaskClass = class of TFormTask;
|
---|
12 |
|
---|
13 | { TApp }
|
---|
14 |
|
---|
15 | TApp = class
|
---|
16 | Name: string;
|
---|
17 | FormClass: TFormTaskClass;
|
---|
18 | end;
|
---|
19 |
|
---|
20 | { TApps }
|
---|
21 |
|
---|
22 | TApps = class(TObjectList<TApp>)
|
---|
23 | function AddNew(Name: string; FormClass: TFormTaskClass): TApp;
|
---|
24 | end;
|
---|
25 |
|
---|
26 | { TTask }
|
---|
27 |
|
---|
28 | TTask = class
|
---|
29 | Form: TFormTask;
|
---|
30 | Terminated: Boolean;
|
---|
31 | destructor Destroy; override;
|
---|
32 | end;
|
---|
33 |
|
---|
34 | { TFormTask }
|
---|
35 |
|
---|
36 | TFormTask = class(TForm)
|
---|
37 | Task: TTask;
|
---|
38 | procedure Terminate;
|
---|
39 | end;
|
---|
40 |
|
---|
41 | { TTasks }
|
---|
42 |
|
---|
43 | TTasks = class(TObjectList<TTask>)
|
---|
44 | private
|
---|
45 | FOnChange: TNotifyEvent;
|
---|
46 | public
|
---|
47 | function AddNew(Form: TFormTask): TTask;
|
---|
48 | function Search(Form: TFormTask): TTask;
|
---|
49 | procedure StartTask(FormClass: TFormTaskClass);
|
---|
50 | procedure DoOnChange;
|
---|
51 | property OnChange: TNotifyEvent read FOnChange write FOnChange;
|
---|
52 | end;
|
---|
53 |
|
---|
54 | { TSystem }
|
---|
55 |
|
---|
56 | TSystem = class
|
---|
57 | Apps: TApps;
|
---|
58 | Tasks: TTasks;
|
---|
59 | ScreenForm: TForm;
|
---|
60 | constructor Create;
|
---|
61 | destructor Destroy; override;
|
---|
62 | procedure ShutDown;
|
---|
63 | procedure Reboot;
|
---|
64 | end;
|
---|
65 |
|
---|
66 | var
|
---|
67 | BaseSystem: TSystem;
|
---|
68 |
|
---|
69 |
|
---|
70 | implementation
|
---|
71 |
|
---|
72 | { TTask }
|
---|
73 |
|
---|
74 | destructor TTask.Destroy;
|
---|
75 | begin
|
---|
76 | Form.Free;
|
---|
77 | inherited;
|
---|
78 | end;
|
---|
79 |
|
---|
80 | { TFormTask }
|
---|
81 |
|
---|
82 | procedure TFormTask.Terminate;
|
---|
83 | begin
|
---|
84 | Task.Terminated := True;
|
---|
85 | Visible := False;
|
---|
86 | BaseSystem.Tasks.DoOnChange;
|
---|
87 | end;
|
---|
88 |
|
---|
89 | { TTasks }
|
---|
90 |
|
---|
91 | function TTasks.AddNew(Form: TFormTask): TTask;
|
---|
92 | begin
|
---|
93 | Result := TTask.Create;
|
---|
94 | Result.Form := Form;
|
---|
95 | Add(Result);
|
---|
96 | end;
|
---|
97 |
|
---|
98 | function TTasks.Search(Form: TFormTask): TTask;
|
---|
99 | var
|
---|
100 | I: Integer;
|
---|
101 | begin
|
---|
102 | I := 0;
|
---|
103 | while (I < Count) and (Items[I].Form <> Form) do Inc(I);
|
---|
104 | if I < Count then Result := Items[I]
|
---|
105 | else Result := nil;
|
---|
106 | end;
|
---|
107 |
|
---|
108 | procedure TTasks.StartTask(FormClass: TFormTaskClass);
|
---|
109 | var
|
---|
110 | Form: TFormTask;
|
---|
111 | Task: TTask;
|
---|
112 | begin
|
---|
113 | Form := FormClass.Create(nil);
|
---|
114 | Task := AddNew(Form);
|
---|
115 | Form.Task := Task;
|
---|
116 | //Form.Parent := BaseSystem.ScreenForm;
|
---|
117 | Form.Show;
|
---|
118 | DoOnChange;
|
---|
119 | end;
|
---|
120 |
|
---|
121 | procedure TTasks.DoOnChange;
|
---|
122 | begin
|
---|
123 | if Assigned(FOnChange) then FOnChange(Self);
|
---|
124 | end;
|
---|
125 |
|
---|
126 | { TApps }
|
---|
127 |
|
---|
128 | function TApps.AddNew(Name: string; FormClass: TFormTaskClass): TApp;
|
---|
129 | begin
|
---|
130 | Result := TApp.Create;
|
---|
131 | Result.Name := Name;
|
---|
132 | Result.FormClass := FormClass;
|
---|
133 | Add(Result);
|
---|
134 | end;
|
---|
135 |
|
---|
136 | { TSystem }
|
---|
137 |
|
---|
138 | constructor TSystem.Create;
|
---|
139 | begin
|
---|
140 | Apps := TApps.Create;
|
---|
141 | Tasks := TTasks.Create;
|
---|
142 | end;
|
---|
143 |
|
---|
144 | destructor TSystem.Destroy;
|
---|
145 | begin
|
---|
146 | Tasks.Free;
|
---|
147 | Apps.Free;
|
---|
148 | inherited;
|
---|
149 | end;
|
---|
150 |
|
---|
151 | procedure TSystem.ShutDown;
|
---|
152 | begin
|
---|
153 | Application.Terminate;
|
---|
154 | end;
|
---|
155 |
|
---|
156 | procedure TSystem.Reboot;
|
---|
157 | begin
|
---|
158 | Tasks.Clear;
|
---|
159 | Tasks.DoOnChange;
|
---|
160 | end;
|
---|
161 |
|
---|
162 | initialization
|
---|
163 |
|
---|
164 | BaseSystem := TSystem.Create;
|
---|
165 |
|
---|
166 | finalization
|
---|
167 |
|
---|
168 | FreeAndNil(BaseSystem);
|
---|
169 |
|
---|
170 | end.
|
---|
171 |
|
---|