Browse Source

* Create key when writing (fix bug ID #25483)

git-svn-id: trunk@26762 -
michael 11 years ago
parent
commit
e65fd31b0b
2 changed files with 7 additions and 5 deletions
  1. 6 4
      packages/fcl-registry/src/regini.inc
  2. 1 1
      packages/fcl-registry/src/registry.pp

+ 6 - 4
packages/fcl-registry/src/regini.inc

@@ -77,7 +77,7 @@ end;
 
 procedure TRegIniFile.WriteBool(const Section, Ident: string; Value: Boolean);
 begin
-  if OpenSection(Section) then
+  if OpenSection(Section,True) then
 	try
     if not fPreferStringValues then
   	  inherited WriteBool(Ident,Value)
@@ -94,7 +94,7 @@ end;
 
 procedure TRegIniFile.WriteInteger(const Section, Ident: string; Value: LongInt);
 begin
-  if OpenSection(Section) then
+  if OpenSection(Section,True) then
   try
     if not fPreferStringValues then
       inherited WriteInteger(Ident,Value)
@@ -111,7 +111,7 @@ end;
 
 procedure TRegIniFile.WriteString(const Section, Ident, Value: String);
 begin
-  if OpenSection(Section) then
+  if OpenSection(Section,True) then
   try
     inherited WriteString(Ident,Value);
   finally
@@ -161,10 +161,12 @@ begin
   end;
 end;
 
-function TRegIniFile.OpenSection(const Section: string): boolean;
+function TRegIniFile.OpenSection(const Section: string; CreateSection : Boolean = false): boolean;
 var
   k: HKEY;
 begin
+  if CreateSection then
+    CreateKey(Section);
   ASSERT(fOldCurKey = 0);
   if Section <> '' then begin
     k:=GetKey(Section);

+ 1 - 1
packages/fcl-registry/src/registry.pp

@@ -134,7 +134,7 @@ type
     fPreferStringValues: Boolean;
     fOldCurKey         : HKEY;
 
-    function OpenSection(const Section: string): boolean;
+    function OpenSection(const Section: string; CreateSection : Boolean = false): boolean;
     procedure CloseSection;
   public
     constructor Create(const FN: string); overload;