Browse Source

* fix for #7411 by forest, implementes TRegIniFile

git-svn-id: trunk@4621 -
florian 19 năm trước cách đây
mục cha
commit
e1a4b9ff11
2 tập tin đã thay đổi với 78 bổ sung9 xóa
  1. 77 9
      fcl/inc/regini.inc
  2. 1 0
      fcl/inc/registry.pp

+ 77 - 9
fcl/inc/regini.inc

@@ -7,59 +7,127 @@ constructor TRegIniFile.Create(const FN: String);
 begin
   inherited Create;
   fFileName := FN;
+  if fFileName<>'' then
+   fPath := fFileName + '\'
+  else
+   fPath := '';
 end;
 
 procedure TRegIniFile.DeleteKey(const Section, Ident: String);
 begin
-
+	if not OpenKey(fPath+Section,true) then Exit;
+	try
+	 DeleteValue(Ident);
+	finally
+	 CloseKey;
+	end;
 end;
 
 procedure TRegIniFile.EraseSection(const Section: string);
 begin
-
+ inherited DeleteKey(fPath+Section);
 end;
 
 procedure TRegIniFile.ReadSection(const Section: string; Strings: TStrings);
 begin
-
+	if not OpenKey(fPath+Section,false) then Exit;
+	try
+	 GetValueNames(Strings);
+	finally
+	 CloseKey;
+	end;
 end;
 
 procedure TRegIniFile.ReadSections(Strings: TStrings);
 begin
-
+	if not OpenKey(fFileName,false) then Exit;
+	try
+	 GetKeyNames(Strings);
+	finally
+	 CloseKey;
+	end;
 end;
 
 procedure TRegIniFile.ReadSectionValues(const Section: string; Strings: TStrings);
+var
+ ValList : TStringList;
+ V : String;
+ i : Integer;
 begin
-
+	if not OpenKey(fPath+Section,false) then Exit;
+	ValList := TStringList.Create;
+	try
+	 GetValueNames(ValList);
+	 for i:=0 to ValList.Count-1 do
+	 begin
+	   V := inherited ReadString(ValList.Strings[i]);
+	   Strings.Add(ValList.Strings[i] + '=' + V);
+	 end;
+	finally
+	 ValList.Free;
+	 CloseKey;
+	end;
 end;
 
 procedure TRegIniFile.WriteBool(const Section, Ident: string; Value: Boolean);
 begin
-
+	if not OpenKey(fPath+Section,true) then Exit;
+	try
+	 inherited WriteBool(Ident,Value);
+	finally
+	 CloseKey;
+	end;
 end;
 
 procedure TRegIniFile.WriteInteger(const Section, Ident: string; Value: LongInt);
 begin
-
+  if not OpenKey(fPath+Section,true) then Exit;
+ try
+  inherited WriteInteger(Ident,Value);
+ finally
+  CloseKey;
+ end;
 end;
 
 procedure TRegIniFile.WriteString(const Section, Ident, Value: String);
 begin
-
+   if not OpenKey(fPath+Section,true) then Exit;
+ try
+   inherited WriteString(Ident,Value);
+ finally
+   CloseKey;
+ end;
 end;
 
 function TRegIniFile.ReadBool(const Section, Ident: string; Default: Boolean): Boolean;
 begin
-  Result := Default;
+	Result := Default;
+	if not OpenKey(fPath+Section,false) then Exit;
+	try
+  	Result := inherited ReadBool(Ident);
+	finally
+	  CloseKey;
+	end;
 end;
 
 function TRegIniFile.ReadInteger(const Section, Ident: string; Default: LongInt): LongInt;
 begin
   Result := Default;
+  if not OpenKey(fPath+Section,false) then Exit;
+  try
+    Result := inherited ReadInteger(Ident);
+  finally
+    CloseKey;
+  end;
 end;
 
 function TRegIniFile.ReadString(const Section, Ident, Default: String): String;
 begin
   Result := Default;
+  if not OpenKey(fPath+Section,false) then Exit;
+  try
+    Result := inherited ReadString(Ident);
+  finally
+    CloseKey;
+  end;
 end;

+ 1 - 0
fcl/inc/registry.pp

@@ -129,6 +129,7 @@ type
   TRegIniFile = class(TRegistry)
   private
     fFileName: String;
+    fPath    : String;
   public
     constructor Create(const FN: string);
     function ReadString(const Section, Ident, Default: string): string;