source: trunk/Packages/fcl-registry/myregistry.pas

Last change on this file was 13, checked in by chronos, 10 years ago
  • Added: Basic parsing of "Depends on" expressions.
File size: 23.7 KB
Line 
1Unit myregistry;
2
3{$mode objfpc}
4{$H+}
5
6interface
7
8{$ifndef windows}
9{$define XMLREG}
10{$endif}
11
12Uses
13 {$ifndef XMLREG}
14 Windows,
15 {$endif XMLREG}
16 Classes,
17 SysUtils,
18 inifiles;
19
20{$I regdef.inc}
21
22type
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
191ResourceString
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
197var
198 GlobalXMLFile : Boolean = False;
199
200implementation
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
218Constructor TRegistry.Create;
219
220begin
221 inherited Create;
222 FAccess := KEY_ALL_ACCESS;
223 FRootKey := HKEY_CURRENT_USER;
224 FLazyWrite := True;
225 FCurrentKey := 0;
226 SysRegCreate;
227end;
228
229Constructor TRegistry.Create(aaccess:longword);
230
231begin
232 Create;
233 FAccess := aaccess;
234end;
235
236Destructor TRegistry.Destroy;
237begin
238 CloseKey;
239 SysRegFree;
240 inherited Destroy;
241end;
242
243function TRegistry.CreateKey(const Key: String): Boolean;
244
245begin
246 Result:=SysCreateKey(Key);
247 If Not Result Then
248 Raise ERegistryException.CreateFmt(SRegCreateFailed, [Key]);
249end;
250
251function TRegistry.GetBaseKey(Relative: Boolean): HKey;
252begin
253 If Relative and (CurrentKey<>0) Then
254 Result := CurrentKey
255 else
256 Result := RootKey;
257end;
258
259function TRegistry.GetData(const Name: String; Buffer: Pointer;
260 BufSize: Integer; var RegData: TRegDataType): Integer;
261begin
262 Result:=SysGetData(Name,Buffer,BufSize,RegData);
263 If (Result=-1) then
264 Raise ERegistryException.CreateFmt(SRegGetDataFailed, [Name]);
265end;
266
267procedure TRegistry.PutData(const Name: string; Buffer: Pointer;
268 BufSize: Integer; RegData: TRegDataType);
269
270begin
271 If Not SysPutData(Name,Buffer,BufSize,RegData) then
272 Raise ERegistryException.CreateFmt(SRegSetDataFailed, [Name]);
273end;
274
275
276function TRegistry.GetDataSize(const ValueName: String): Integer;
277
278Var
279 Info: TRegDataInfo;
280
281begin
282 If GetDataInfo(ValueName,Info) Then
283 Result := Info.DataSize
284 else
285 Result := -1;
286end;
287
288function TRegistry.GetDataType(const ValueName: string): TRegDataType;
289
290Var
291 Info: TRegDataInfo;
292
293begin
294 GetDataInfo(ValueName, Info);
295 Result:=Info.RegData;
296end;
297
298Function TRegistry.HasSubKeys: Boolean;
299
300Var
301 Info : TRegKeyInfo;
302
303begin
304 Result:=GetKeyInfo(Info);
305 If Result then
306 Result:=(Info.NumSubKeys>0);
307end;
308
309function TRegistry.ReadBinaryData(const Name: string; var Buffer; BufSize: Integer): Integer;
310
311Var
312 RegDataType: TRegDataType;
313
314begin
315 Result := GetData(Name, @Buffer, BufSize, RegDataType);
316 If (RegDataType<>rdBinary) Then
317 Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
318end;
319
320function TRegistry.ReadInteger(const Name: string): Integer;
321
322Var
323 RegDataType: TRegDataType;
324
325begin
326 GetData(Name, @Result, SizeOf(Integer), RegDataType);
327 If RegDataType<>rdInteger Then
328 Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
329end;
330
331function TRegistry.ReadBool(const Name: string): Boolean;
332
333begin
334 Result:=ReadInteger(Name)<>0;
335end;
336
337function TRegistry.ReadCurrency(const Name: string): Currency;
338
339Var
340 RegDataType: TRegDataType;
341
342begin
343 ReadBinaryData(Name, Result, SizeOf(Currency));
344end;
345
346function TRegistry.ReadDate(const Name: string): TDateTime;
347
348begin
349 ReadBinaryData(Name, Result, SizeOf(TDateTime));
350 Result:=Trunc(Result);
351end;
352
353function TRegistry.ReadDateTime(const Name: string): TDateTime;
354Var
355 RegDataType: TRegDataType;
356
357begin
358 ReadBinaryData(Name, Result, SizeOf(TDateTime));
359end;
360
361function TRegistry.ReadFloat(const Name: string): Double;
362
363begin
364 ReadBinaryData(Name,Result,SizeOf(Double));
365end;
366
367function TRegistry.ReadString(const Name: string): string;
368
369Var
370 Info : TRegDataInfo;
371
372begin
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:='';
387end;
388
389function TRegistry.ReadTime(const Name: string): TDateTime;
390
391begin
392 ReadBinaryData(Name, Result, SizeOf(TDateTime));
393 Result:=Frac(Result);
394end;
395
396procedure TRegistry.WriteBinaryData(const Name: string; var Buffer; BufSize: Integer);
397begin
398 PutData(Name, @Buffer, BufSize, rdBinary);
399end;
400
401procedure TRegistry.WriteBool(const Name: string; Value: Boolean);
402
403begin
404 WriteInteger(Name,Ord(Value));
405end;
406
407procedure TRegistry.WriteCurrency(const Name: string; Value: Currency);
408begin
409 WriteBinaryData(Name, Value, SizeOf(Currency));
410end;
411
412procedure TRegistry.WriteDate(const Name: string; Value: TDateTime);
413begin
414 WriteBinarydata(Name, Value, SizeOf(TDateTime));
415end;
416
417procedure TRegistry.WriteTime(const Name: string; Value: TDateTime);
418begin
419 WriteBinaryData(Name, Value, SizeOf(TDateTime));
420end;
421
422procedure TRegistry.WriteDateTime(const Name: string; Value: TDateTime);
423begin
424 WriteBinaryData(Name, Value, SizeOf(TDateTime));
425end;
426
427procedure TRegistry.WriteExpandString(const Name, Value: string);
428
429begin
430 PutData(Name, PChar(Value), Length(Value),rdExpandString);
431end;
432
433procedure TRegistry.WriteFloat(const Name: string; Value: Double);
434begin
435 WriteBinaryData(Name, Value, SizeOf(Double));
436end;
437
438procedure TRegistry.WriteInteger(const Name: string; Value: Integer);
439begin
440 PutData(Name, @Value, SizeOf(Integer), rdInteger);
441end;
442
443procedure TRegistry.WriteString(const Name, Value: string);
444
445begin
446 PutData(Name, PChar(Value), Length(Value), rdString);
447end;
448
449procedure TRegistry.MoveKey(const OldName, NewName: string; Delete: Boolean);
450begin
451
452end;
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
464constructor TRegistryIniFile.Create(const AFileName: string;
465 AAccess: LongWord);
466begin
467 inherited create(AFilename);
468 FRegInifile:=TreginiFile.Create(AFileName,AAccess);
469end;
470
471constructor TRegistryIniFile.Create(const AFileName: string);
472begin
473 Create(AFileName,KEY_ALL_ACCESS);
474end;
475
476procedure TRegistryIniFile.DeleteKey(const Section, Name: String);
477begin
478 FRegIniFile.Deletekey(section,name);
479end;
480
481procedure TRegistryIniFile.EraseSection(const Section: string);
482begin
483 FRegIniFile.EraseSection(section);
484end;
485
486function TRegistryIniFile.ReadBinaryStream(const Section, Name: string;
487 Value: TStream): Integer;
488begin
489 result:=-1; // unimplemented
490 //
491end;
492
493function TRegistryIniFile.ReadDate(const Section, Name: string;
494 Default: TDateTime): TDateTime;
495var sectkey,curkey : HKey;
496begin
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;
520end;
521
522function TRegistryIniFile.ReadDateTime(const Section, Name: string;
523 Default: TDateTime): TDateTime;
524var sectkey,curkey : HKey;
525begin
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;
549end;
550
551function TRegistryIniFile.ReadFloat(const Section, Name: string;
552 Default: Double): Double;
553var sectkey,curkey : HKey;
554begin
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;
578end;
579
580function TRegistryIniFile.ReadInteger(const Section, Name: string;
581 Default: Integer): Longint;
582var sectkey,curkey : HKey;
583begin
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;
607end;
608
609procedure TRegistryIniFile.ReadSection(const Section: string;
610 Strings: TStrings);
611begin
612 FRegIniFile.ReadSection(Section,strings);
613end;
614
615procedure TRegistryIniFile.ReadSections(Strings: TStrings);
616begin
617 FRegIniFile.ReadSections(strings);
618end;
619
620procedure TRegistryIniFile.ReadSectionValues(const Section: string;
621 Strings: TStrings);
622begin
623 FRegIniFile.ReadSectionValues(Section,strings);
624end;
625
626function TRegistryIniFile.ReadString(const Section, Name,
627 Default: string): string;
628var sectkey,curkey : HKey;
629begin
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;
653end;
654
655function TRegistryIniFile.ReadTime(const Section, Name: string;
656 Default: TDateTime): TDateTime;
657var sectkey,curkey : HKey;
658begin
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;
682end;
683
684procedure TRegistryIniFile.UpdateFile;
685begin
686// FRegIniFile.UpdateFile; ??
687end;
688
689procedure TRegistryIniFile.WriteBinaryStream(const Section, Name: string;
690 Value: TStream);
691begin
692 // ??
693end;
694
695procedure TRegistryIniFile.WriteDate(const Section, Name: string;
696 Value: TDateTime);
697var sectkey,curkey : HKey;
698begin
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;
717end;
718
719procedure TRegistryIniFile.WriteDateTime(const Section, Name: string;
720 Value: TDateTime);
721var sectkey,curkey : HKey;
722begin
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;
741end;
742
743procedure TRegistryIniFile.WriteFloat(const Section, Name: string;
744 Value: Double);
745var sectkey,curkey : HKey;
746begin
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;
765end;
766
767procedure TRegistryIniFile.WriteInteger(const Section, Name: string;
768 Value: Integer);
769var sectkey,curkey : HKey;
770begin
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
790end;
791
792procedure TRegistryIniFile.WriteString(const Section, Name, Value: String);
793var sectkey,curkey : HKey;
794begin
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;
813end;
814
815procedure TRegistryIniFile.WriteTime(const Section, Name: string;
816 Value: TDateTime);
817var sectkey,curkey : HKey;
818begin
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;
837end;
838
839end.
Note: See TracBrowser for help on using the repository browser.