1 | Unit myregistry;
|
---|
2 |
|
---|
3 | {$mode objfpc}
|
---|
4 | {$H+}
|
---|
5 |
|
---|
6 | interface
|
---|
7 |
|
---|
8 | {$ifndef windows}
|
---|
9 | {$define XMLREG}
|
---|
10 | {$endif}
|
---|
11 |
|
---|
12 | Uses
|
---|
13 | {$ifndef XMLREG}
|
---|
14 | Windows,
|
---|
15 | {$endif XMLREG}
|
---|
16 | Classes,
|
---|
17 | SysUtils,
|
---|
18 | inifiles;
|
---|
19 |
|
---|
20 | {$I regdef.inc}
|
---|
21 |
|
---|
22 | type
|
---|
23 | ERegistryException = class(Exception);
|
---|
24 |
|
---|
25 | TRegKeyInfo = record
|
---|
26 | NumSubKeys: Integer;
|
---|
27 | MaxSubKeyLen: Integer;
|
---|
28 | NumValues: Integer;
|
---|
29 | MaxValueLen: Integer;
|
---|
30 | MaxDataLen: Integer;
|
---|
31 | FileTime: TDateTime;
|
---|
32 | end;
|
---|
33 |
|
---|
34 | TRegDataType = (rdUnknown, rdString, rdExpandString, rdBinary, rdInteger);
|
---|
35 |
|
---|
36 | TRegDataInfo = record
|
---|
37 | RegData: TRegDataType;
|
---|
38 | DataSize: Integer;
|
---|
39 | end;
|
---|
40 |
|
---|
41 | { ---------------------------------------------------------------------
|
---|
42 | TRegistry
|
---|
43 | ---------------------------------------------------------------------}
|
---|
44 |
|
---|
45 | TRegistry = class(TObject)
|
---|
46 | private
|
---|
47 | FStringSizeIncludesNull : Boolean;
|
---|
48 | FSysData : Pointer;
|
---|
49 | fAccess: LongWord;
|
---|
50 | fCurrentKey: HKEY;
|
---|
51 | fRootKey: HKEY;
|
---|
52 | fLazyWrite: Boolean;
|
---|
53 | fCurrentPath: string;
|
---|
54 | procedure SetRootKey(Value: HKEY);
|
---|
55 | Procedure SysRegCreate;
|
---|
56 | Procedure SysRegFree;
|
---|
57 | Function SysGetData(const Name: String; Buffer: Pointer; BufSize: Integer; var RegData: TRegDataType): Integer;
|
---|
58 | Function SysPutData(const Name: string; Buffer: Pointer; BufSize: Integer; RegData: TRegDataType) : Boolean;
|
---|
59 | Function SysCreateKey(const Key: String): Boolean;
|
---|
60 | protected
|
---|
61 | function GetBaseKey(Relative: Boolean): HKey;
|
---|
62 | function GetData(const Name: string; Buffer: Pointer;
|
---|
63 | BufSize: Integer; var RegData: TRegDataType): Integer;
|
---|
64 | function GetKey(const Key: string): HKEY;
|
---|
65 | procedure ChangeKey(Value: HKey; const Path: string);
|
---|
66 | procedure PutData(const Name: string; Buffer: Pointer;
|
---|
67 | BufSize: Integer; RegData: TRegDataType);
|
---|
68 | procedure SetCurrentKey(Value: HKEY);
|
---|
69 | public
|
---|
70 | constructor Create; overload;
|
---|
71 | constructor Create(aaccess:longword); overload;
|
---|
72 | destructor Destroy; override;
|
---|
73 |
|
---|
74 | function CreateKey(const Key: string): Boolean;
|
---|
75 | function DeleteKey(const Key: string): Boolean;
|
---|
76 | function DeleteValue(const Name: string): Boolean;
|
---|
77 | function GetDataInfo(const ValueName: string; var Value: TRegDataInfo): Boolean;
|
---|
78 | function GetDataSize(const ValueName: string): Integer;
|
---|
79 | function GetDataType(const ValueName: string): TRegDataType;
|
---|
80 | function GetKeyInfo(var Value: TRegKeyInfo): Boolean;
|
---|
81 | function HasSubKeys: Boolean;
|
---|
82 | function KeyExists(const Key: string): Boolean;
|
---|
83 | function LoadKey(const Key, FileName: string): Boolean;
|
---|
84 | function OpenKey(const Key: string; CanCreate: Boolean): Boolean;
|
---|
85 | function OpenKeyReadOnly(const Key: string): Boolean;
|
---|
86 | function ReadCurrency(const Name: string): Currency;
|
---|
87 | function ReadBinaryData(const Name: string; var Buffer; BufSize: Integer): Integer;
|
---|
88 | function ReadBool(const Name: string): Boolean;
|
---|
89 | function ReadDate(const Name: string): TDateTime;
|
---|
90 | function ReadDateTime(const Name: string): TDateTime;
|
---|
91 | function ReadFloat(const Name: string): Double;
|
---|
92 | function ReadInteger(const Name: string): Integer;
|
---|
93 | function ReadString(const Name: string): string;
|
---|
94 | function ReadTime(const Name: string): TDateTime;
|
---|
95 | function RegistryConnect(const UNCName: string): Boolean;
|
---|
96 | function ReplaceKey(const Key, FileName, BackUpFileName: string): Boolean;
|
---|
97 | function RestoreKey(const Key, FileName: string): Boolean;
|
---|
98 | function SaveKey(const Key, FileName: string): Boolean;
|
---|
99 | function UnLoadKey(const Key: string): Boolean;
|
---|
100 | function ValueExists(const Name: string): Boolean;
|
---|
101 |
|
---|
102 | procedure CloseKey;
|
---|
103 | procedure CloseKey(key:HKEY);
|
---|
104 | procedure GetKeyNames(Strings: TStrings);
|
---|
105 | procedure GetValueNames(Strings: TStrings);
|
---|
106 | procedure MoveKey(const OldName, NewName: string; Delete: Boolean);
|
---|
107 | procedure RenameValue(const OldName, NewName: string);
|
---|
108 | procedure WriteCurrency(const Name: string; Value: Currency);
|
---|
109 | procedure WriteBinaryData(const Name: string; var Buffer; BufSize: Integer);
|
---|
110 | procedure WriteBool(const Name: string; Value: Boolean);
|
---|
111 | procedure WriteDate(const Name: string; Value: TDateTime);
|
---|
112 | procedure WriteDateTime(const Name: string; Value: TDateTime);
|
---|
113 | procedure WriteFloat(const Name: string; Value: Double);
|
---|
114 | procedure WriteInteger(const Name: string; Value: Integer);
|
---|
115 | procedure WriteString(const Name, Value: string);
|
---|
116 | procedure WriteExpandString(const Name, Value: string);
|
---|
117 | procedure WriteTime(const Name: string; Value: TDateTime);
|
---|
118 |
|
---|
119 | property Access: LongWord read fAccess write fAccess;
|
---|
120 | property CurrentKey: HKEY read fCurrentKey;
|
---|
121 | property CurrentPath: string read fCurrentPath;
|
---|
122 | property LazyWrite: Boolean read fLazyWrite write fLazyWrite;
|
---|
123 | property RootKey: HKEY read fRootKey write SetRootKey;
|
---|
124 | Property StringSizeIncludesNull : Boolean read FStringSizeIncludesNull;
|
---|
125 | end;
|
---|
126 |
|
---|
127 | { ---------------------------------------------------------------------
|
---|
128 | TRegIniFile
|
---|
129 | ---------------------------------------------------------------------}
|
---|
130 | TRegIniFile = class(TRegistry)
|
---|
131 | private
|
---|
132 | fFileName : String;
|
---|
133 | fPath : String;
|
---|
134 | fPreferStringValues: Boolean;
|
---|
135 | public
|
---|
136 | constructor Create(const FN: string); overload;
|
---|
137 | constructor Create(const FN: string;aaccess:longword); overload;
|
---|
138 | function ReadString(const Section, Ident, Default: string): string;
|
---|
139 | function ReadInteger(const Section, Ident: string;
|
---|
140 | Default: Longint): Longint;
|
---|
141 | function ReadBool(const Section, Ident: string; Default: Boolean): Boolean;
|
---|
142 |
|
---|
143 | procedure WriteString(const Section, Ident, Value: String);
|
---|
144 | procedure WriteInteger(const Section, Ident: string; Value: Longint);
|
---|
145 | procedure WriteBool(const Section, Ident: string; Value: Boolean);
|
---|
146 | procedure ReadSection(const Section: string; Strings: TStrings);
|
---|
147 | procedure ReadSections(Strings: TStrings);
|
---|
148 | procedure ReadSectionValues(const Section: string; Strings: TStrings);
|
---|
149 | procedure EraseSection(const Section: string);
|
---|
150 | procedure DeleteKey(const Section, Ident: String);
|
---|
151 |
|
---|
152 | property FileName: String read fFileName;
|
---|
153 | property PreferStringValues: Boolean read fPreferStringValues
|
---|
154 | write fPreferStringValues;
|
---|
155 | end;
|
---|
156 |
|
---|
157 | { ---------------------------------------------------------------------
|
---|
158 | TRegIniFile
|
---|
159 | ---------------------------------------------------------------------}
|
---|
160 |
|
---|
161 |
|
---|
162 | TRegistryIniFile = class(TCustomIniFile)
|
---|
163 | private
|
---|
164 | FRegIniFile: TRegIniFile;
|
---|
165 | public
|
---|
166 | constructor Create(const AFileName: string); overload;
|
---|
167 | constructor Create(const AFileName: string; AAccess: LongWord); overload;
|
---|
168 | function ReadDate(const Section, Name: string; Default: TDateTime): TDateTime; override;
|
---|
169 | function ReadDateTime(const Section, Name: string; Default: TDateTime): TDateTime; override;
|
---|
170 | function ReadInteger(const Section, Name: string; Default: Longint): Longint; override;
|
---|
171 | function ReadFloat(const Section, Name: string; Default: Double): Double; override;
|
---|
172 | function ReadString(const Section, Name, Default: string): string; override;
|
---|
173 | function ReadTime(const Section, Name: string; Default: TDateTime): TDateTime; override;
|
---|
174 | function ReadBinaryStream(const Section, Name: string; Value: TStream): Integer; override;
|
---|
175 | procedure WriteDate(const Section, Name: string; Value: TDateTime); override;
|
---|
176 | procedure WriteDateTime(const Section, Name: string; Value: TDateTime); override;
|
---|
177 | procedure WriteFloat(const Section, Name: string; Value: Double); override;
|
---|
178 | procedure WriteInteger(const Section, Name: string; Value: Longint); override;
|
---|
179 | procedure WriteString(const Section, Name, Value: String); override;
|
---|
180 | procedure WriteTime(const Section, Name: string; Value: TDateTime); override;
|
---|
181 | procedure WriteBinaryStream(const Section, Name: string; Value: TStream); override;
|
---|
182 | procedure ReadSection(const Section: string; Strings: TStrings); override;
|
---|
183 | procedure ReadSections(Strings: TStrings); override;
|
---|
184 | procedure ReadSectionValues(const Section: string; Strings: TStrings); override;
|
---|
185 | procedure EraseSection(const Section: string); override;
|
---|
186 | procedure DeleteKey(const Section, Name: String); override;
|
---|
187 | procedure UpdateFile; override;
|
---|
188 | property RegIniFile: TRegIniFile read FRegIniFile;
|
---|
189 | end;
|
---|
190 |
|
---|
191 | ResourceString
|
---|
192 | SInvalidRegType = 'Invalid registry data type: "%s"';
|
---|
193 | SRegCreateFailed = 'Failed to create key: "%s"';
|
---|
194 | SRegSetDataFailed = 'Failed to set data for value "%s"';
|
---|
195 | SRegGetDataFailed = 'Failed to get data for value "%s"';
|
---|
196 |
|
---|
197 | var
|
---|
198 | GlobalXMLFile : Boolean = False;
|
---|
199 |
|
---|
200 | implementation
|
---|
201 |
|
---|
202 | { ---------------------------------------------------------------------
|
---|
203 | Include implementation-dependent code
|
---|
204 | ---------------------------------------------------------------------}
|
---|
205 |
|
---|
206 |
|
---|
207 | {$ifdef XMLREG}
|
---|
208 | {$i xregreg.inc}
|
---|
209 | {$else}
|
---|
210 | {$i winreg.inc}
|
---|
211 | {$endif}
|
---|
212 |
|
---|
213 | { ---------------------------------------------------------------------
|
---|
214 | Generic, implementation-independent code.
|
---|
215 | ---------------------------------------------------------------------}
|
---|
216 |
|
---|
217 |
|
---|
218 | Constructor TRegistry.Create;
|
---|
219 |
|
---|
220 | begin
|
---|
221 | inherited Create;
|
---|
222 | FAccess := KEY_ALL_ACCESS;
|
---|
223 | FRootKey := HKEY_CURRENT_USER;
|
---|
224 | FLazyWrite := True;
|
---|
225 | FCurrentKey := 0;
|
---|
226 | SysRegCreate;
|
---|
227 | end;
|
---|
228 |
|
---|
229 | Constructor TRegistry.Create(aaccess:longword);
|
---|
230 |
|
---|
231 | begin
|
---|
232 | Create;
|
---|
233 | FAccess := aaccess;
|
---|
234 | end;
|
---|
235 |
|
---|
236 | Destructor TRegistry.Destroy;
|
---|
237 | begin
|
---|
238 | CloseKey;
|
---|
239 | SysRegFree;
|
---|
240 | inherited Destroy;
|
---|
241 | end;
|
---|
242 |
|
---|
243 | function TRegistry.CreateKey(const Key: String): Boolean;
|
---|
244 |
|
---|
245 | begin
|
---|
246 | Result:=SysCreateKey(Key);
|
---|
247 | If Not Result Then
|
---|
248 | Raise ERegistryException.CreateFmt(SRegCreateFailed, [Key]);
|
---|
249 | end;
|
---|
250 |
|
---|
251 | function TRegistry.GetBaseKey(Relative: Boolean): HKey;
|
---|
252 | begin
|
---|
253 | If Relative and (CurrentKey<>0) Then
|
---|
254 | Result := CurrentKey
|
---|
255 | else
|
---|
256 | Result := RootKey;
|
---|
257 | end;
|
---|
258 |
|
---|
259 | function TRegistry.GetData(const Name: String; Buffer: Pointer;
|
---|
260 | BufSize: Integer; var RegData: TRegDataType): Integer;
|
---|
261 | begin
|
---|
262 | Result:=SysGetData(Name,Buffer,BufSize,RegData);
|
---|
263 | If (Result=-1) then
|
---|
264 | Raise ERegistryException.CreateFmt(SRegGetDataFailed, [Name]);
|
---|
265 | end;
|
---|
266 |
|
---|
267 | procedure TRegistry.PutData(const Name: string; Buffer: Pointer;
|
---|
268 | BufSize: Integer; RegData: TRegDataType);
|
---|
269 |
|
---|
270 | begin
|
---|
271 | If Not SysPutData(Name,Buffer,BufSize,RegData) then
|
---|
272 | Raise ERegistryException.CreateFmt(SRegSetDataFailed, [Name]);
|
---|
273 | end;
|
---|
274 |
|
---|
275 |
|
---|
276 | function TRegistry.GetDataSize(const ValueName: String): Integer;
|
---|
277 |
|
---|
278 | Var
|
---|
279 | Info: TRegDataInfo;
|
---|
280 |
|
---|
281 | begin
|
---|
282 | If GetDataInfo(ValueName,Info) Then
|
---|
283 | Result := Info.DataSize
|
---|
284 | else
|
---|
285 | Result := -1;
|
---|
286 | end;
|
---|
287 |
|
---|
288 | function TRegistry.GetDataType(const ValueName: string): TRegDataType;
|
---|
289 |
|
---|
290 | Var
|
---|
291 | Info: TRegDataInfo;
|
---|
292 |
|
---|
293 | begin
|
---|
294 | GetDataInfo(ValueName, Info);
|
---|
295 | Result:=Info.RegData;
|
---|
296 | end;
|
---|
297 |
|
---|
298 | Function TRegistry.HasSubKeys: Boolean;
|
---|
299 |
|
---|
300 | Var
|
---|
301 | Info : TRegKeyInfo;
|
---|
302 |
|
---|
303 | begin
|
---|
304 | Result:=GetKeyInfo(Info);
|
---|
305 | If Result then
|
---|
306 | Result:=(Info.NumSubKeys>0);
|
---|
307 | end;
|
---|
308 |
|
---|
309 | function TRegistry.ReadBinaryData(const Name: string; var Buffer; BufSize: Integer): Integer;
|
---|
310 |
|
---|
311 | Var
|
---|
312 | RegDataType: TRegDataType;
|
---|
313 |
|
---|
314 | begin
|
---|
315 | Result := GetData(Name, @Buffer, BufSize, RegDataType);
|
---|
316 | If (RegDataType<>rdBinary) Then
|
---|
317 | Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
|
---|
318 | end;
|
---|
319 |
|
---|
320 | function TRegistry.ReadInteger(const Name: string): Integer;
|
---|
321 |
|
---|
322 | Var
|
---|
323 | RegDataType: TRegDataType;
|
---|
324 |
|
---|
325 | begin
|
---|
326 | GetData(Name, @Result, SizeOf(Integer), RegDataType);
|
---|
327 | If RegDataType<>rdInteger Then
|
---|
328 | Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
|
---|
329 | end;
|
---|
330 |
|
---|
331 | function TRegistry.ReadBool(const Name: string): Boolean;
|
---|
332 |
|
---|
333 | begin
|
---|
334 | Result:=ReadInteger(Name)<>0;
|
---|
335 | end;
|
---|
336 |
|
---|
337 | function TRegistry.ReadCurrency(const Name: string): Currency;
|
---|
338 |
|
---|
339 | Var
|
---|
340 | RegDataType: TRegDataType;
|
---|
341 |
|
---|
342 | begin
|
---|
343 | ReadBinaryData(Name, Result, SizeOf(Currency));
|
---|
344 | end;
|
---|
345 |
|
---|
346 | function TRegistry.ReadDate(const Name: string): TDateTime;
|
---|
347 |
|
---|
348 | begin
|
---|
349 | ReadBinaryData(Name, Result, SizeOf(TDateTime));
|
---|
350 | Result:=Trunc(Result);
|
---|
351 | end;
|
---|
352 |
|
---|
353 | function TRegistry.ReadDateTime(const Name: string): TDateTime;
|
---|
354 | Var
|
---|
355 | RegDataType: TRegDataType;
|
---|
356 |
|
---|
357 | begin
|
---|
358 | ReadBinaryData(Name, Result, SizeOf(TDateTime));
|
---|
359 | end;
|
---|
360 |
|
---|
361 | function TRegistry.ReadFloat(const Name: string): Double;
|
---|
362 |
|
---|
363 | begin
|
---|
364 | ReadBinaryData(Name,Result,SizeOf(Double));
|
---|
365 | end;
|
---|
366 |
|
---|
367 | function TRegistry.ReadString(const Name: string): string;
|
---|
368 |
|
---|
369 | Var
|
---|
370 | Info : TRegDataInfo;
|
---|
371 |
|
---|
372 | begin
|
---|
373 | GetDataInfo(Name,Info);
|
---|
374 | if info.datasize>0 then
|
---|
375 | begin
|
---|
376 | If Not (Info.RegData in [rdString,rdExpandString]) then
|
---|
377 | Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
|
---|
378 | SetLength(Result,Info.DataSize);
|
---|
379 | If StringSizeIncludesNull then
|
---|
380 | SetLength(Result, Info.DataSize-1)
|
---|
381 | else
|
---|
382 | SetLength(Result, Info.DataSize);
|
---|
383 | GetData(Name,PChar(Result),Info.DataSize,Info.RegData);
|
---|
384 | end
|
---|
385 | else
|
---|
386 | result:='';
|
---|
387 | end;
|
---|
388 |
|
---|
389 | function TRegistry.ReadTime(const Name: string): TDateTime;
|
---|
390 |
|
---|
391 | begin
|
---|
392 | ReadBinaryData(Name, Result, SizeOf(TDateTime));
|
---|
393 | Result:=Frac(Result);
|
---|
394 | end;
|
---|
395 |
|
---|
396 | procedure TRegistry.WriteBinaryData(const Name: string; var Buffer; BufSize: Integer);
|
---|
397 | begin
|
---|
398 | PutData(Name, @Buffer, BufSize, rdBinary);
|
---|
399 | end;
|
---|
400 |
|
---|
401 | procedure TRegistry.WriteBool(const Name: string; Value: Boolean);
|
---|
402 |
|
---|
403 | begin
|
---|
404 | WriteInteger(Name,Ord(Value));
|
---|
405 | end;
|
---|
406 |
|
---|
407 | procedure TRegistry.WriteCurrency(const Name: string; Value: Currency);
|
---|
408 | begin
|
---|
409 | WriteBinaryData(Name, Value, SizeOf(Currency));
|
---|
410 | end;
|
---|
411 |
|
---|
412 | procedure TRegistry.WriteDate(const Name: string; Value: TDateTime);
|
---|
413 | begin
|
---|
414 | WriteBinarydata(Name, Value, SizeOf(TDateTime));
|
---|
415 | end;
|
---|
416 |
|
---|
417 | procedure TRegistry.WriteTime(const Name: string; Value: TDateTime);
|
---|
418 | begin
|
---|
419 | WriteBinaryData(Name, Value, SizeOf(TDateTime));
|
---|
420 | end;
|
---|
421 |
|
---|
422 | procedure TRegistry.WriteDateTime(const Name: string; Value: TDateTime);
|
---|
423 | begin
|
---|
424 | WriteBinaryData(Name, Value, SizeOf(TDateTime));
|
---|
425 | end;
|
---|
426 |
|
---|
427 | procedure TRegistry.WriteExpandString(const Name, Value: string);
|
---|
428 |
|
---|
429 | begin
|
---|
430 | PutData(Name, PChar(Value), Length(Value),rdExpandString);
|
---|
431 | end;
|
---|
432 |
|
---|
433 | procedure TRegistry.WriteFloat(const Name: string; Value: Double);
|
---|
434 | begin
|
---|
435 | WriteBinaryData(Name, Value, SizeOf(Double));
|
---|
436 | end;
|
---|
437 |
|
---|
438 | procedure TRegistry.WriteInteger(const Name: string; Value: Integer);
|
---|
439 | begin
|
---|
440 | PutData(Name, @Value, SizeOf(Integer), rdInteger);
|
---|
441 | end;
|
---|
442 |
|
---|
443 | procedure TRegistry.WriteString(const Name, Value: string);
|
---|
444 |
|
---|
445 | begin
|
---|
446 | PutData(Name, PChar(Value), Length(Value), rdString);
|
---|
447 | end;
|
---|
448 |
|
---|
449 | procedure TRegistry.MoveKey(const OldName, NewName: string; Delete: Boolean);
|
---|
450 | begin
|
---|
451 |
|
---|
452 | end;
|
---|
453 |
|
---|
454 | { ---------------------------------------------------------------------
|
---|
455 | Include TRegIniFile implementation
|
---|
456 | ---------------------------------------------------------------------}
|
---|
457 |
|
---|
458 | {$i regini.inc}
|
---|
459 |
|
---|
460 | { TRegistryIniFile }
|
---|
461 |
|
---|
462 | // interface from
|
---|
463 | // http://www.koders.com/delphi/fid65C1FFAEF89B0CDC4B93FF94C1819686CA6141FC.aspx
|
---|
464 | constructor TRegistryIniFile.Create(const AFileName: string;
|
---|
465 | AAccess: LongWord);
|
---|
466 | begin
|
---|
467 | inherited create(AFilename);
|
---|
468 | FRegInifile:=TreginiFile.Create(AFileName,AAccess);
|
---|
469 | end;
|
---|
470 |
|
---|
471 | constructor TRegistryIniFile.Create(const AFileName: string);
|
---|
472 | begin
|
---|
473 | Create(AFileName,KEY_ALL_ACCESS);
|
---|
474 | end;
|
---|
475 |
|
---|
476 | procedure TRegistryIniFile.DeleteKey(const Section, Name: String);
|
---|
477 | begin
|
---|
478 | FRegIniFile.Deletekey(section,name);
|
---|
479 | end;
|
---|
480 |
|
---|
481 | procedure TRegistryIniFile.EraseSection(const Section: string);
|
---|
482 | begin
|
---|
483 | FRegIniFile.EraseSection(section);
|
---|
484 | end;
|
---|
485 |
|
---|
486 | function TRegistryIniFile.ReadBinaryStream(const Section, Name: string;
|
---|
487 | Value: TStream): Integer;
|
---|
488 | begin
|
---|
489 | result:=-1; // unimplemented
|
---|
490 | //
|
---|
491 | end;
|
---|
492 |
|
---|
493 | function TRegistryIniFile.ReadDate(const Section, Name: string;
|
---|
494 | Default: TDateTime): TDateTime;
|
---|
495 | var sectkey,curkey : HKey;
|
---|
496 | begin
|
---|
497 | with FRegInifile do
|
---|
498 | begin
|
---|
499 | sectkey:=getkey(Section);
|
---|
500 | if sectkey<>0 then
|
---|
501 | begin
|
---|
502 | try // allocation ok
|
---|
503 | curkey:=FRegIniFile.CurrentKey;
|
---|
504 | SetCurrentKey(sectKey);
|
---|
505 | try // save current key
|
---|
506 | if ValueExists(Name) THen
|
---|
507 | result:=FRegIniFile.ReadDate(Name)
|
---|
508 | else
|
---|
509 | result:=default;
|
---|
510 | finally
|
---|
511 | SetCurrentKey(CurKey);
|
---|
512 | end;
|
---|
513 | finally
|
---|
514 | closekey(sectkey);
|
---|
515 | end;
|
---|
516 | end
|
---|
517 | else
|
---|
518 | result:=default;
|
---|
519 | end;
|
---|
520 | end;
|
---|
521 |
|
---|
522 | function TRegistryIniFile.ReadDateTime(const Section, Name: string;
|
---|
523 | Default: TDateTime): TDateTime;
|
---|
524 | var sectkey,curkey : HKey;
|
---|
525 | begin
|
---|
526 | with FRegInifile do
|
---|
527 | begin
|
---|
528 | sectkey:=getkey(Section);
|
---|
529 | if sectkey<>0 then
|
---|
530 | begin
|
---|
531 | try // allocation ok
|
---|
532 | curkey:=FRegIniFile.CurrentKey;
|
---|
533 | SetCurrentKey(sectKey);
|
---|
534 | try // save current key
|
---|
535 | if ValueExists(Name) THen
|
---|
536 | result:=FRegIniFile.ReadDateTime(Name)
|
---|
537 | else
|
---|
538 | result:=default;
|
---|
539 | finally
|
---|
540 | SetCurrentKey(CurKey);
|
---|
541 | end;
|
---|
542 | finally
|
---|
543 | closekey(sectkey);
|
---|
544 | end;
|
---|
545 | end
|
---|
546 | else
|
---|
547 | result:=default;
|
---|
548 | end;
|
---|
549 | end;
|
---|
550 |
|
---|
551 | function TRegistryIniFile.ReadFloat(const Section, Name: string;
|
---|
552 | Default: Double): Double;
|
---|
553 | var sectkey,curkey : HKey;
|
---|
554 | begin
|
---|
555 | with FRegInifile do
|
---|
556 | begin
|
---|
557 | sectkey:=getkey(Section);
|
---|
558 | if sectkey<>0 then
|
---|
559 | begin
|
---|
560 | try // allocation ok
|
---|
561 | curkey:=FRegIniFile.CurrentKey;
|
---|
562 | SetCurrentKey(sectKey);
|
---|
563 | try // save current key
|
---|
564 | if ValueExists(Name) THen
|
---|
565 | result:=FRegIniFile.ReadFloat(Name)
|
---|
566 | else
|
---|
567 | result:=default;
|
---|
568 | finally
|
---|
569 | SetCurrentKey(CurKey);
|
---|
570 | end;
|
---|
571 | finally
|
---|
572 | closekey(sectkey);
|
---|
573 | end;
|
---|
574 | end
|
---|
575 | else
|
---|
576 | result:=default;
|
---|
577 | end;
|
---|
578 | end;
|
---|
579 |
|
---|
580 | function TRegistryIniFile.ReadInteger(const Section, Name: string;
|
---|
581 | Default: Integer): Longint;
|
---|
582 | var sectkey,curkey : HKey;
|
---|
583 | begin
|
---|
584 | with FRegInifile do
|
---|
585 | begin
|
---|
586 | sectkey:=getkey(Section);
|
---|
587 | if sectkey<>0 then
|
---|
588 | begin
|
---|
589 | try // allocation ok
|
---|
590 | curkey:=FRegIniFile.CurrentKey;
|
---|
591 | SetCurrentKey(sectKey);
|
---|
592 | try // save current key
|
---|
593 | if ValueExists(Name) THen
|
---|
594 | result:=FRegIniFile.ReadInteger(section,Name,default)
|
---|
595 | else
|
---|
596 | result:=default;
|
---|
597 | finally
|
---|
598 | SetCurrentKey(CurKey);
|
---|
599 | end;
|
---|
600 | finally
|
---|
601 | closekey(sectkey);
|
---|
602 | end;
|
---|
603 | end
|
---|
604 | else
|
---|
605 | result:=default;
|
---|
606 | end;
|
---|
607 | end;
|
---|
608 |
|
---|
609 | procedure TRegistryIniFile.ReadSection(const Section: string;
|
---|
610 | Strings: TStrings);
|
---|
611 | begin
|
---|
612 | FRegIniFile.ReadSection(Section,strings);
|
---|
613 | end;
|
---|
614 |
|
---|
615 | procedure TRegistryIniFile.ReadSections(Strings: TStrings);
|
---|
616 | begin
|
---|
617 | FRegIniFile.ReadSections(strings);
|
---|
618 | end;
|
---|
619 |
|
---|
620 | procedure TRegistryIniFile.ReadSectionValues(const Section: string;
|
---|
621 | Strings: TStrings);
|
---|
622 | begin
|
---|
623 | FRegIniFile.ReadSectionValues(Section,strings);
|
---|
624 | end;
|
---|
625 |
|
---|
626 | function TRegistryIniFile.ReadString(const Section, Name,
|
---|
627 | Default: string): string;
|
---|
628 | var sectkey,curkey : HKey;
|
---|
629 | begin
|
---|
630 | with FRegInifile do
|
---|
631 | begin
|
---|
632 | sectkey:=getkey(Section);
|
---|
633 | if sectkey<>0 then
|
---|
634 | begin
|
---|
635 | try // allocation ok
|
---|
636 | curkey:=FRegIniFile.CurrentKey;
|
---|
637 | SetCurrentKey(sectKey);
|
---|
638 | try // save current key
|
---|
639 | if ValueExists(Name) THen
|
---|
640 | result:=FRegIniFile.ReadString(section,Name,default)
|
---|
641 | else
|
---|
642 | result:=default;
|
---|
643 | finally
|
---|
644 | SetCurrentKey(CurKey);
|
---|
645 | end;
|
---|
646 | finally
|
---|
647 | closekey(sectkey);
|
---|
648 | end;
|
---|
649 | end
|
---|
650 | else
|
---|
651 | result:=default;
|
---|
652 | end;
|
---|
653 | end;
|
---|
654 |
|
---|
655 | function TRegistryIniFile.ReadTime(const Section, Name: string;
|
---|
656 | Default: TDateTime): TDateTime;
|
---|
657 | var sectkey,curkey : HKey;
|
---|
658 | begin
|
---|
659 | with FRegInifile do
|
---|
660 | begin
|
---|
661 | sectkey:=getkey(Section);
|
---|
662 | if sectkey<>0 then
|
---|
663 | begin
|
---|
664 | try // allocation ok
|
---|
665 | curkey:=FRegIniFile.CurrentKey;
|
---|
666 | SetCurrentKey(sectKey);
|
---|
667 | try // save current key
|
---|
668 | if ValueExists(Name) THen
|
---|
669 | result:=FRegIniFile.ReadTime(Name)
|
---|
670 | else
|
---|
671 | result:=default;
|
---|
672 | finally
|
---|
673 | SetCurrentKey(CurKey);
|
---|
674 | end;
|
---|
675 | finally
|
---|
676 | closekey(sectkey);
|
---|
677 | end;
|
---|
678 | end
|
---|
679 | else
|
---|
680 | result:=default;
|
---|
681 | end;
|
---|
682 | end;
|
---|
683 |
|
---|
684 | procedure TRegistryIniFile.UpdateFile;
|
---|
685 | begin
|
---|
686 | // FRegIniFile.UpdateFile; ??
|
---|
687 | end;
|
---|
688 |
|
---|
689 | procedure TRegistryIniFile.WriteBinaryStream(const Section, Name: string;
|
---|
690 | Value: TStream);
|
---|
691 | begin
|
---|
692 | // ??
|
---|
693 | end;
|
---|
694 |
|
---|
695 | procedure TRegistryIniFile.WriteDate(const Section, Name: string;
|
---|
696 | Value: TDateTime);
|
---|
697 | var sectkey,curkey : HKey;
|
---|
698 | begin
|
---|
699 | with FRegInifile do
|
---|
700 | begin
|
---|
701 | sectkey:=getkey(Section);
|
---|
702 | if sectkey<>0 then
|
---|
703 | begin
|
---|
704 | try // allocation ok
|
---|
705 | curkey:=FRegIniFile.CurrentKey;
|
---|
706 | SetCurrentKey(sectKey);
|
---|
707 | try // save current key
|
---|
708 | FRegIniFile.WriteDate(name,value)
|
---|
709 | finally
|
---|
710 | SetCurrentKey(CurKey);
|
---|
711 | end;
|
---|
712 | finally
|
---|
713 | closekey(sectkey);
|
---|
714 | end;
|
---|
715 | end
|
---|
716 | end;
|
---|
717 | end;
|
---|
718 |
|
---|
719 | procedure TRegistryIniFile.WriteDateTime(const Section, Name: string;
|
---|
720 | Value: TDateTime);
|
---|
721 | var sectkey,curkey : HKey;
|
---|
722 | begin
|
---|
723 | with FRegInifile do
|
---|
724 | begin
|
---|
725 | sectkey:=getkey(Section);
|
---|
726 | if sectkey<>0 then
|
---|
727 | begin
|
---|
728 | try // allocation ok
|
---|
729 | curkey:=FRegIniFile.CurrentKey;
|
---|
730 | SetCurrentKey(sectKey);
|
---|
731 | try // save current key
|
---|
732 | FRegIniFile.WriteDateTime(Name,value)
|
---|
733 | finally
|
---|
734 | SetCurrentKey(CurKey);
|
---|
735 | end;
|
---|
736 | finally
|
---|
737 | closekey(sectkey);
|
---|
738 | end;
|
---|
739 | end
|
---|
740 | end;
|
---|
741 | end;
|
---|
742 |
|
---|
743 | procedure TRegistryIniFile.WriteFloat(const Section, Name: string;
|
---|
744 | Value: Double);
|
---|
745 | var sectkey,curkey : HKey;
|
---|
746 | begin
|
---|
747 | with FRegInifile do
|
---|
748 | begin
|
---|
749 | sectkey:=getkey(Section);
|
---|
750 | if sectkey<>0 then
|
---|
751 | begin
|
---|
752 | try // allocation ok
|
---|
753 | curkey:=FRegIniFile.CurrentKey;
|
---|
754 | SetCurrentKey(sectKey);
|
---|
755 | try // save current key
|
---|
756 | FRegIniFile.WriteFloat(Name,value)
|
---|
757 | finally
|
---|
758 | SetCurrentKey(CurKey);
|
---|
759 | end;
|
---|
760 | finally
|
---|
761 | closekey(sectkey);
|
---|
762 | end;
|
---|
763 | end
|
---|
764 | end;
|
---|
765 | end;
|
---|
766 |
|
---|
767 | procedure TRegistryIniFile.WriteInteger(const Section, Name: string;
|
---|
768 | Value: Integer);
|
---|
769 | var sectkey,curkey : HKey;
|
---|
770 | begin
|
---|
771 | with FRegInifile do
|
---|
772 | begin
|
---|
773 | sectkey:=getkey(Section);
|
---|
774 | if sectkey<>0 then
|
---|
775 | begin
|
---|
776 | try // allocation ok
|
---|
777 | curkey:=FRegIniFile.CurrentKey;
|
---|
778 | SetCurrentKey(sectKey);
|
---|
779 | try // save current key
|
---|
780 | FRegIniFile.WriteInteger(section,Name,value)
|
---|
781 | finally
|
---|
782 | SetCurrentKey(CurKey);
|
---|
783 | end;
|
---|
784 | finally
|
---|
785 | closekey(sectkey);
|
---|
786 | end;
|
---|
787 | end
|
---|
788 | end;
|
---|
789 |
|
---|
790 | end;
|
---|
791 |
|
---|
792 | procedure TRegistryIniFile.WriteString(const Section, Name, Value: String);
|
---|
793 | var sectkey,curkey : HKey;
|
---|
794 | begin
|
---|
795 | with FRegInifile do
|
---|
796 | begin
|
---|
797 | sectkey:=getkey(Section);
|
---|
798 | if sectkey<>0 then
|
---|
799 | begin
|
---|
800 | try // allocation ok
|
---|
801 | curkey:=FRegIniFile.CurrentKey;
|
---|
802 | SetCurrentKey(sectKey);
|
---|
803 | try // save current key
|
---|
804 | FRegIniFile.WriteString(section,Name,value)
|
---|
805 | finally
|
---|
806 | SetCurrentKey(CurKey);
|
---|
807 | end;
|
---|
808 | finally
|
---|
809 | closekey(sectkey);
|
---|
810 | end;
|
---|
811 | end
|
---|
812 | end;
|
---|
813 | end;
|
---|
814 |
|
---|
815 | procedure TRegistryIniFile.WriteTime(const Section, Name: string;
|
---|
816 | Value: TDateTime);
|
---|
817 | var sectkey,curkey : HKey;
|
---|
818 | begin
|
---|
819 | with FRegInifile do
|
---|
820 | begin
|
---|
821 | sectkey:=getkey(Section);
|
---|
822 | if sectkey<>0 then
|
---|
823 | begin
|
---|
824 | try // allocation ok
|
---|
825 | curkey:=FRegIniFile.CurrentKey;
|
---|
826 | SetCurrentKey(sectKey);
|
---|
827 | try // save current key
|
---|
828 | FRegIniFile.WriteTime(Name,value)
|
---|
829 | finally
|
---|
830 | SetCurrentKey(CurKey);
|
---|
831 | end;
|
---|
832 | finally
|
---|
833 | closekey(sectkey);
|
---|
834 | end;
|
---|
835 | end
|
---|
836 | end;
|
---|
837 | end;
|
---|
838 |
|
---|
839 | end.
|
---|