source: trunk/UCore.pas

Last change on this file was 23, checked in by chronos, 12 years ago
  • Přidáno: Rozpracovaná třídy pro komunikaci s přístupovým terminálem BF-630. Přiložen popis protokolu.
File size: 3.9 KB
Line 
1unit UCore;
2
3{$mode delphi}
4
5interface
6
7uses
8 Registry, Classes, SysUtils, FileUtil, USqlDatabase, URegistry, Forms,
9 UApplicationInfo, UCoolTranslator, UPersistentForm, UModularSystem,
10 UFormModuleList;
11
12type
13
14 { TCore }
15
16 TCore = class(TDataModule)
17 ApplicationInfo1: TApplicationInfo;
18 CoolTranslator1: TCoolTranslator;
19 Database: TSqlDatabase;
20 ModuleManager: TModuleManager;
21 procedure DataModuleCreate(Sender: TObject);
22 procedure DataModuleDestroy(Sender: TObject);
23 procedure ModuleManagerUpdate(Sender: TObject);
24 private
25 public
26 FormModuleList: TFormModuleList;
27 FormList: TForm;
28 PersistentForm: TPersistentForm;
29 RegistryContext: TRegistryContext;
30 procedure Init;
31 procedure Done;
32 procedure InitData;
33 procedure Connect;
34 procedure LoadFromRegistry(AContext: TRegistryContext);
35 procedure SaveToRegistry(AContext: TRegistryContext);
36 end;
37
38var
39 Core: TCore;
40
41implementation
42
43{$R *.lfm}
44
45uses
46 URegistredModules, UFormMain;
47
48
49{ TCore }
50
51procedure TCore.DataModuleCreate(Sender: TObject);
52begin
53 PersistentForm := TPersistentForm.Create;
54 PersistentForm.RegistryContext := RegContext(HKEY(ApplicationInfo1.RegistryRoot),
55 ApplicationInfo1.RegistryKey + '\Forms');
56 RegistryContext := RegContext(HKEY(ApplicationInfo1.RegistryRoot), ApplicationInfo1.RegistryKey);
57end;
58
59procedure TCore.DataModuleDestroy(Sender: TObject);
60begin
61 FreeAndNil(PersistentForm);
62end;
63
64procedure TCore.ModuleManagerUpdate(Sender: TObject);
65begin
66 if Assigned(FormModuleList) then
67 FormModuleList.Reload;
68 FormMain.ReloadPages;
69end;
70
71procedure TCore.Init;
72begin
73 LoadFromRegistry(RegistryContext);
74
75 try
76 ModuleManager.Modules.BeginUpdate;
77
78 // Init modules
79 with TRegistryEx.Create do
80 try
81 Context := RegistryContext;
82 RegisterModules(ModuleManager);
83 if ReadBoolWithDefault('ModuleManagerInstalled', False) then
84 ModuleManager.LoadFromRegistry(RegContext(RegistryContext.RootKey, RegistryContext.Key + '\Modules'))
85 else begin
86 ModuleManager.Modules.Perform([maEnable]);
87 ModuleManager.SaveToRegistry(RegContext(RegistryContext.RootKey, RegistryContext.Key + '\Modules'));
88 WriteBool('ModuleManagerInstalled', True);
89 end;
90 finally
91 Free;
92 end;
93 ModuleManager.Modules.Perform([maStart], [mcEnabled]);
94 finally
95 ModuleManager.Modules.EndUpdate;
96 end;
97end;
98
99procedure TCore.Done;
100begin
101 SaveToRegistry(RegistryContext);
102 FormMain.Hide; // Speed up undocking with hidden main form
103 ModuleManager.SaveToRegistry(RegContext(RegistryContext.RootKey, RegistryContext.Key + '\Modules'));
104 if Assigned(FormModuleList) then FreeAndNil(FormModuleList);
105 ModuleManager.OnUpdate := nil;
106 UnregisterModules(ModuleManager);
107end;
108
109procedure TCore.InitData;
110var
111 DbRows: TDbRows;
112begin
113 try
114 DbRows := TDbRows.Create;
115 Database.Query(DbRows, '');
116 finally
117 DbRows.Free;
118 end;
119end;
120
121procedure TCore.Connect;
122begin
123 Database.Connect;
124end;
125
126procedure TCore.LoadFromRegistry(AContext: TRegistryContext);
127begin
128 with TRegistryEx.Create do
129 try
130 Context := AContext;
131 Database.HostName := ReadStringWithDefault('HostName', 'localhost');
132 Database.Database := ReadStringWithDefault('Schema', 'dochazka');
133 Database.UserName := ReadStringWithDefault('UserName', 'dochazka');
134 Database.Password := ReadStringWithDefault('Password', '');
135 CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(ReadStringWithDefault('Language', ''));
136 finally
137 Free;
138 end;
139end;
140
141procedure TCore.SaveToRegistry(AContext: TRegistryContext);
142begin
143 with TRegistryEx.Create do
144 try
145 Context := AContext;
146 WriteString('HostName', Database.HostName);
147 WriteString('Schema', Database.Database);
148 WriteString('UserName', Database.UserName);
149 WriteString('Password', Database.Password);
150 WriteString('Language', CoolTranslator1.Language.Code);
151 finally
152 Free;
153 end;
154end;
155
156end.
157
Note: See TracBrowser for help on using the repository browser.