1 | unit UFormMain;
|
---|
2 |
|
---|
3 | {$mode delphi}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
|
---|
9 | ActnList, ComCtrls, ExtCtrls, UGeneralRegistry;
|
---|
10 |
|
---|
11 | type
|
---|
12 |
|
---|
13 | { TFormMain }
|
---|
14 |
|
---|
15 | TFormMain = class(TForm)
|
---|
16 | AConnectionAdd: TAction;
|
---|
17 | AConnectionDelete: TAction;
|
---|
18 | AConnectionModify: TAction;
|
---|
19 | AValueAdd: TAction;
|
---|
20 | AValueEdit: TAction;
|
---|
21 | AValueDelete: TAction;
|
---|
22 | AImport: TAction;
|
---|
23 | AExport: TAction;
|
---|
24 | ActionList1: TActionList;
|
---|
25 | ListView1: TListView;
|
---|
26 | MainMenu1: TMainMenu;
|
---|
27 | MenuItem1: TMenuItem;
|
---|
28 | MenuItem2: TMenuItem;
|
---|
29 | MenuItem3: TMenuItem;
|
---|
30 | MenuItem4: TMenuItem;
|
---|
31 | MenuItem5: TMenuItem;
|
---|
32 | MenuItem6: TMenuItem;
|
---|
33 | PopupMenuValue: TPopupMenu;
|
---|
34 | Splitter1: TSplitter;
|
---|
35 | StatusBar1: TStatusBar;
|
---|
36 | TreeView1: TTreeView;
|
---|
37 | procedure AConnectionAddExecute(Sender: TObject);
|
---|
38 | procedure AValueAddExecute(Sender: TObject);
|
---|
39 | procedure AValueDeleteExecute(Sender: TObject);
|
---|
40 | procedure AValueEditExecute(Sender: TObject);
|
---|
41 | procedure FormShow(Sender: TObject);
|
---|
42 | procedure ListView1Data(Sender: TObject; Item: TListItem);
|
---|
43 | procedure ListView1DblClick(Sender: TObject);
|
---|
44 | private
|
---|
45 | function RegValueToString(ValueName: string): string;
|
---|
46 | procedure LoadNode(Node: TTreeNode; Key: TRegKey);
|
---|
47 | procedure ReloadTreeNode(Node: TTreeNode; Reg: TGeneralRegistry);
|
---|
48 | public
|
---|
49 | procedure ReloadValues;
|
---|
50 | procedure ReloadKeys;
|
---|
51 | end;
|
---|
52 |
|
---|
53 | var
|
---|
54 | FormMain: TFormMain;
|
---|
55 |
|
---|
56 |
|
---|
57 | implementation
|
---|
58 |
|
---|
59 | uses
|
---|
60 | UCore, UFormValue;
|
---|
61 |
|
---|
62 | {$R *.lfm}
|
---|
63 |
|
---|
64 | { TFormMain }
|
---|
65 |
|
---|
66 | procedure TFormMain.ListView1Data(Sender: TObject; Item: TListItem);
|
---|
67 | var
|
---|
68 | KeyInfo: TRegKeyInfo;
|
---|
69 | ValueInfo: TRegValueInfo;
|
---|
70 | ValueNames: TStringList;
|
---|
71 | begin
|
---|
72 | try
|
---|
73 | ValueNames := TStringList.Create;
|
---|
74 | Core.ActiveRegistry.GetKeyInfo(KeyInfo);
|
---|
75 | if (Item.Index >= 0) and (Item.Index < KeyInfo.NumberValues) then begin
|
---|
76 | Core.ActiveRegistry.GetValueNames(ValueNames);
|
---|
77 | Item.Caption := ValueNames[Item.Index];
|
---|
78 | Core.ActiveRegistry.GetValueInfo(ValueNames[Item.Index], ValueInfo);
|
---|
79 | Item.SubItems.Add(RegValueTypeName[ValueInfo.ValueType]);
|
---|
80 | Item.SubItems.Add(RegValueToString(ValueNames[Item.Index]));
|
---|
81 | end;
|
---|
82 | finally
|
---|
83 | ValueNames.Free;
|
---|
84 | end;
|
---|
85 | end;
|
---|
86 |
|
---|
87 | procedure TFormMain.ListView1DblClick(Sender: TObject);
|
---|
88 | begin
|
---|
89 | AValueEdit.Execute;
|
---|
90 | end;
|
---|
91 |
|
---|
92 | procedure TFormMain.FormShow(Sender: TObject);
|
---|
93 | begin
|
---|
94 | ReloadKeys;
|
---|
95 | ReloadValues;
|
---|
96 | end;
|
---|
97 |
|
---|
98 |
|
---|
99 | procedure TFormMain.AConnectionAddExecute(Sender: TObject);
|
---|
100 | begin
|
---|
101 | end;
|
---|
102 |
|
---|
103 | procedure TFormMain.AValueDeleteExecute(Sender: TObject);
|
---|
104 | var
|
---|
105 | I: Integer;
|
---|
106 | begin
|
---|
107 | if MessageDlg('Delete value', 'Do you want to delete value?', mtConfirmation,
|
---|
108 | [mbCancel, mbOk], 0) = mrOk then begin
|
---|
109 | for I := ListView1.Items.Count - 1 downto 0 do
|
---|
110 | if ListView1.Items[I].Selected then begin
|
---|
111 | ListView1.Items[I].Selected := False;
|
---|
112 | Core.ActiveRegistry.DeleteValue(ListView1.Items[I].Caption);
|
---|
113 | end;
|
---|
114 | ReloadValues;
|
---|
115 | end;
|
---|
116 | end;
|
---|
117 |
|
---|
118 | procedure TFormMain.AValueAddExecute(Sender: TObject);
|
---|
119 | var
|
---|
120 | FormValue: TFormValue;
|
---|
121 | begin
|
---|
122 | FormValue := TFormValue.Create(nil);
|
---|
123 | FormValue.EditName.Text := 'New value';
|
---|
124 | FormValue.EditName.Enabled := True;
|
---|
125 | FormValue.SetValueType(vtString);
|
---|
126 | if FormValue.ShowModal = mrOk then begin
|
---|
127 | if FormValue.GetValueType = vtString then
|
---|
128 | Core.ActiveRegistry.WriteString(FormValue.EditName.Text, FormValue.EditValue.Text)
|
---|
129 | else if FormValue.GetValueType = vtInteger then
|
---|
130 | Core.ActiveRegistry.WriteInteger(FormValue.EditName.Text, FormValue.SpinEditValue.Value)
|
---|
131 | else if FormValue.GetValueType = vtBoolean then
|
---|
132 | Core.ActiveRegistry.WriteBool(FormValue.EditName.Text, FormValue.CheckBoxValue.Checked)
|
---|
133 | else raise Exception.Create('Unsupported type ' + RegValueTypeName[TRegValueType(FormValue.ComboBoxType.ItemIndex)]);
|
---|
134 | ReloadValues;
|
---|
135 | end;
|
---|
136 | FormValue.Free;
|
---|
137 | end;
|
---|
138 |
|
---|
139 | procedure TFormMain.AValueEditExecute(Sender: TObject);
|
---|
140 | var
|
---|
141 | FormValue: TFormValue;
|
---|
142 | ValueInfo: TRegValueInfo;
|
---|
143 | PrevValueType: TRegValueType;
|
---|
144 | begin
|
---|
145 | FormValue := TFormValue.Create(nil);
|
---|
146 | FormValue.EditName.Text := ListView1.Selected.Caption;
|
---|
147 | FormValue.EditName.Enabled := False;
|
---|
148 | Core.ActiveRegistry.GetValueInfo(ListView1.Selected.Caption, ValueInfo);
|
---|
149 | PrevValueType := ValueInfo.ValueType;
|
---|
150 | FormValue.SetValueType(ValueInfo.ValueType);
|
---|
151 | if PrevValueType = vtString then
|
---|
152 | FormValue.EditValue.Text := Core.ActiveRegistry.ReadString(ListView1.Selected.Caption)
|
---|
153 | else if PrevValueType = vtInteger then
|
---|
154 | FormValue.SpinEditValue.Value := Core.ActiveRegistry.ReadInteger(ListView1.Selected.Caption)
|
---|
155 | else if PrevValueType = vtBoolean then
|
---|
156 | FormValue.CheckBoxValue.Checked := Core.ActiveRegistry.ReadBool(ListView1.Selected.Caption);
|
---|
157 | if FormValue.ShowModal = mrOk then begin
|
---|
158 | if FormValue.GetValueType <> PrevValueType then
|
---|
159 | Core.ActiveRegistry.DeleteValue(FormValue.EditName.Text);
|
---|
160 | if FormValue.GetValueType = vtString then
|
---|
161 | Core.ActiveRegistry.WriteString(FormValue.EditName.Text, FormValue.EditValue.Text)
|
---|
162 | else if FormValue.GetValueType = vtInteger then
|
---|
163 | Core.ActiveRegistry.WriteInteger(FormValue.EditName.Text, FormValue.SpinEditValue.Value)
|
---|
164 | else if FormValue.GetValueType = vtBoolean then
|
---|
165 | Core.ActiveRegistry.WriteBool(FormValue.EditName.Text, FormValue.CheckBoxValue.Checked)
|
---|
166 | else raise Exception.Create('Unsupported type ' + RegValueTypeName[TRegValueType(FormValue.ComboBoxType.ItemIndex)]);
|
---|
167 | ReloadValues;
|
---|
168 | end;
|
---|
169 | FormValue.Free;
|
---|
170 | end;
|
---|
171 |
|
---|
172 | function TFormMain.RegValueToString(ValueName: string): string;
|
---|
173 | var
|
---|
174 | ValueType: TRegValueType;
|
---|
175 | Buffer: array of Byte;
|
---|
176 | I: Integer;
|
---|
177 | begin
|
---|
178 | with Core.ActiveRegistry do begin
|
---|
179 | ValueType := GetValueType(ValueName);
|
---|
180 | case ValueType of
|
---|
181 | vtBoolean: if ReadBool(ValueName) then Result := 'True' else Result := 'False';
|
---|
182 | vtInteger: Result := IntToStr(ReadInteger(ValueName));
|
---|
183 | vtString: Result := ReadString(ValueName);
|
---|
184 | vtFloat: Result := FloatToStr(ReadFloat(ValueName));
|
---|
185 | vtUnknown: Result := '?';
|
---|
186 | vtText: Result := ReadString(ValueName);
|
---|
187 | vtBinary: begin
|
---|
188 | SetLength(Buffer, GetValueSize(ValueName));
|
---|
189 | ReadBinaryData(ValueName, PByte(Buffer)^, Length(Buffer));
|
---|
190 | Result := '';
|
---|
191 | for I := 0 to Length(Buffer) - 1 do begin
|
---|
192 | Result := Result + IntToHex(Buffer[I], 2);
|
---|
193 | if I < Length(Buffer) - 1 then Result := Result + ' ';
|
---|
194 | end;
|
---|
195 | end;
|
---|
196 | end;
|
---|
197 | end;
|
---|
198 | end;
|
---|
199 |
|
---|
200 | procedure TFormMain.LoadNode(Node: TTreeNode; Key: TRegKey);
|
---|
201 | begin
|
---|
202 |
|
---|
203 | end;
|
---|
204 |
|
---|
205 | procedure TFormMain.ReloadValues;
|
---|
206 | var
|
---|
207 | KeyInfo: TRegKeyInfo;
|
---|
208 | begin
|
---|
209 | if Core.ActiveRegistry.GetKeyInfo(KeyInfo) then
|
---|
210 | ListView1.Items.Count := KeyInfo.NumberValues
|
---|
211 | else ListView1.Items.Count := 0;
|
---|
212 | ListView1.Refresh;
|
---|
213 | end;
|
---|
214 |
|
---|
215 | procedure TFormMain.ReloadTreeNode(Node: TTreeNode; Reg: TGeneralRegistry);
|
---|
216 | var
|
---|
217 | Keys: TStrings;
|
---|
218 | I: Integer;
|
---|
219 | NewNode: TTreeNode;
|
---|
220 | begin
|
---|
221 | Keys := TStringList.Create;
|
---|
222 | Reg.GetKeyNames(Keys);
|
---|
223 | for I := 0 to Keys.Count - 1 do begin
|
---|
224 | NewNode := Node.TreeNodes.AddChild(Node, Keys[I]);
|
---|
225 | Reg.OpenKey(Keys[I], False);
|
---|
226 | ReloadTreeNode(NewNode, Reg);
|
---|
227 | end;
|
---|
228 | Keys.Free;
|
---|
229 | end;
|
---|
230 |
|
---|
231 | procedure TFormMain.ReloadKeys;
|
---|
232 | var
|
---|
233 | NewNode: TTreeNode;
|
---|
234 | begin
|
---|
235 | TreeView1.Items.Clear;
|
---|
236 | NewNode := TreeView1.Items.AddChild(nil, 'Local computer');
|
---|
237 | ReloadTreeNode(NewNode, Core.ActiveRegistry);
|
---|
238 | NewNode.Expand(True);
|
---|
239 | end;
|
---|
240 |
|
---|
241 | end.
|
---|
242 |
|
---|