Browse Source

* Patch from Stephano so TRegIniFile can process registry values written by Delphi

git-svn-id: trunk@17206 -
michael 14 years ago
parent
commit
bc2bebfa16
2 changed files with 39 additions and 16 deletions
  1. 34 14
      packages/fcl-registry/src/regini.inc
  2. 5 2
      packages/fcl-registry/src/registry.pp

+ 34 - 14
packages/fcl-registry/src/regini.inc

@@ -83,30 +83,44 @@ procedure TRegIniFile.WriteBool(const Section, Ident: string; Value: Boolean);
 begin
 begin
 	if not OpenKey(fPath+Section,true) then Exit;
 	if not OpenKey(fPath+Section,true) then Exit;
 	try
 	try
-	 inherited WriteBool(Ident,Value);
-	finally
-	 CloseKey;
+    if not fPreferStringValues then
+  	  inherited WriteBool(Ident,Value)
+    else begin
+      if ValueExists(Ident) and (GetDataType(Ident)=rdInteger) then
+    	  inherited WriteBool(Ident,Value)
+      else
+        inherited WriteString(Ident,BoolToStr(Value));
+    end;
+  finally
+	  CloseKey;
 	end;
 	end;
 end;
 end;
 
 
 procedure TRegIniFile.WriteInteger(const Section, Ident: string; Value: LongInt);
 procedure TRegIniFile.WriteInteger(const Section, Ident: string; Value: LongInt);
 begin
 begin
   if not OpenKey(fPath+Section,true) then Exit;
   if not OpenKey(fPath+Section,true) then Exit;
- try
-  inherited WriteInteger(Ident,Value);
- finally
-  CloseKey;
- end;
+  try
+    if not fPreferStringValues then
+      inherited WriteInteger(Ident,Value)
+    else begin
+      if ValueExists(Ident) and (GetDataType(Ident)=rdInteger) then
+    	  inherited WriteInteger(Ident,Value)
+      else
+        inherited WriteString(Ident,IntToStr(Value));
+    end;
+  finally
+    CloseKey;
+  end;
 end;
 end;
 
 
 procedure TRegIniFile.WriteString(const Section, Ident, Value: String);
 procedure TRegIniFile.WriteString(const Section, Ident, Value: String);
 begin
 begin
-   if not OpenKey(fPath+Section,true) then Exit;
- try
+  if not OpenKey(fPath+Section,true) then Exit;
+  try
    inherited WriteString(Ident,Value);
    inherited WriteString(Ident,Value);
- finally
+  finally
    CloseKey;
    CloseKey;
- end;
+  end;
 end;
 end;
 
 
 function TRegIniFile.ReadBool(const Section, Ident: string; Default: Boolean): Boolean;
 function TRegIniFile.ReadBool(const Section, Ident: string; Default: Boolean): Boolean;
@@ -115,7 +129,10 @@ begin
 	if not OpenKey(fPath+Section,false) then Exit;
 	if not OpenKey(fPath+Section,false) then Exit;
 	try
 	try
     if ValueExists(Ident) then
     if ValueExists(Ident) then
-	    Result := inherited ReadBool(Ident);
+      if (not fPreferStringValues) or (GetDataType(Ident)=rdInteger) then
+  	    Result := inherited ReadBool(Ident)
+      else
+        Result := StrToBool(inherited ReadString(Ident));
 	finally
 	finally
 	  CloseKey;
 	  CloseKey;
 	end;
 	end;
@@ -127,7 +144,10 @@ begin
   if not OpenKey(fPath+Section,false) then Exit;
   if not OpenKey(fPath+Section,false) then Exit;
   try
   try
     if ValueExists(Ident) then
     if ValueExists(Ident) then
-      Result := inherited ReadInteger(Ident);
+      if (not fPreferStringValues) or (GetDataType(Ident)=rdInteger) then
+        Result := inherited ReadInteger(Ident)
+      else
+        Result := StrToInt(inherited ReadString(Ident));
   finally
   finally
     CloseKey;
     CloseKey;
   end;
   end;

+ 5 - 2
packages/fcl-registry/src/registry.pp

@@ -130,8 +130,9 @@ type
   ---------------------------------------------------------------------}
   ---------------------------------------------------------------------}
   TRegIniFile = class(TRegistry)
   TRegIniFile = class(TRegistry)
   private
   private
-    fFileName: String;
-    fPath    : String;
+    fFileName          : String;
+    fPath              : String;
+    fPreferStringValues: Boolean;
   public
   public
     constructor Create(const FN: string); overload;
     constructor Create(const FN: string); overload;
     constructor Create(const FN: string;aaccess:longword); overload;
     constructor Create(const FN: string;aaccess:longword); overload;
@@ -150,6 +151,8 @@ type
     procedure DeleteKey(const Section, Ident: String);
     procedure DeleteKey(const Section, Ident: String);
 
 
     property FileName: String read fFileName;
     property FileName: String read fFileName;
+    property PreferStringValues: Boolean read fPreferStringValues
+                write fPreferStringValues;
   end;
   end;
 
 
 { ---------------------------------------------------------------------
 { ---------------------------------------------------------------------