| Attached Files | patch.diff [^] (16,158 bytes) 2012-08-09 14:26 [Show Content] [Hide Content]Index: regini.inc
===================================================================
--- regini.inc (revision 22046)
+++ regini.inc (working copy)
@@ -3,6 +3,7 @@
TRegIniFile
******************************************************************************}
+
constructor TRegIniFile.Create(const FN: String);
begin
inherited Create;
@@ -96,6 +97,77 @@
end;
end;
+procedure TRegIniFile.WriteDate(const Section, Ident: string; Value: TDateTime
+ );
+begin
+ if not OpenKey(fPath+Section,true) then Exit;
+ try
+ if not fPreferStringValues then
+ inherited WriteDate(Ident,Value)
+ else begin
+ if ValueExists(Ident) and (GetDataType(Ident)<>rdString) then
+ inherited WriteDate(Ident,Value)
+ else
+ inherited WriteString(Ident,DateToStr(Value));
+ end;
+ finally
+ CloseKey;
+ end;
+end;
+
+procedure TRegIniFile.WriteDateTime(const Section, Ident: string;
+ Value: TDateTime);
+begin
+ if not OpenKey(fPath+Section,true) then Exit;
+ try
+ if not fPreferStringValues then
+ inherited WriteDateTime(Ident,Value)
+ else begin
+ if ValueExists(Ident) and (GetDataType(Ident)<>rdString) then
+ inherited WriteDateTime(Ident,Value)
+ else
+ inherited WriteString(Ident,DateTimeToStr(Value));
+ end;
+ finally
+ CloseKey;
+ end;
+end;
+
+procedure TRegIniFile.WriteTime(const Section, Ident: string; Value: TDateTime
+ );
+begin
+ if not OpenKey(fPath+Section,true) then Exit;
+ try
+ if not fPreferStringValues then
+ inherited WriteTime(Ident,Value)
+ else begin
+ if ValueExists(Ident) and (GetDataType(Ident)<>rdString) then
+ inherited WriteTime(Ident,Value)
+ else
+ inherited WriteString(Ident,TimeToStr(Value));
+ end;
+ finally
+ CloseKey;
+ end;
+end;
+
+procedure TRegIniFile.WriteFloat(const Section, Ident: string; Value: Double);
+begin
+ if not OpenKey(fPath+Section,true) then Exit;
+ try
+ if not fPreferStringValues then
+ inherited WriteFloat(Ident,Value)
+ else begin
+ if ValueExists(Ident) and (GetDataType(Ident)<>rdString) then
+ inherited WriteFloat(Ident,Value)
+ else
+ inherited WriteString(Ident,FloatToStr(Value));
+ end;
+ finally
+ CloseKey;
+ end;
+end;
+
procedure TRegIniFile.WriteInteger(const Section, Ident: string; Value: LongInt);
begin
if not OpenKey(fPath+Section,true) then Exit;
@@ -138,6 +210,70 @@
end;
end;
+function TRegIniFile.ReadDate(const Section, Ident: string; Default: TDateTime
+ ): TDateTime;
+begin
+ Result := Default;
+ if not OpenKey(fPath+Section,false) then Exit;
+ try
+ if ValueExists(Ident) then
+ if (not fPreferStringValues) or (GetDataType(Ident)<>rdString) then
+ Result := inherited ReadDate(Ident)
+ else
+ Result := StrToDate(inherited ReadString(Ident));
+ finally
+ CloseKey;
+ end;
+end;
+
+function TRegIniFile.ReadDateTime(const Section, Ident: string;
+ Default: TDateTime): TDateTime;
+begin
+ Result := Default;
+ if not OpenKey(fPath+Section,false) then Exit;
+ try
+ if ValueExists(Ident) then
+ if (not fPreferStringValues) or (GetDataType(Ident)<>rdString) then
+ Result := inherited ReadDateTime(Ident)
+ else
+ Result := StrToDateTime(inherited ReadString(Ident));
+ finally
+ CloseKey;
+ end;
+end;
+
+function TRegIniFile.ReadTime(const Section, Ident: string; Default: TDateTime
+ ): TDateTime;
+begin
+ Result := Default;
+ if not OpenKey(fPath+Section,false) then Exit;
+ try
+ if ValueExists(Ident) then
+ if (not fPreferStringValues) or (GetDataType(Ident)<>rdString) then
+ Result := inherited ReadTime(Ident)
+ else
+ Result := StrToTime(inherited ReadString(Ident));
+ finally
+ CloseKey;
+ end;
+end;
+
+function TRegIniFile.ReadFloat(const Section, Ident: string; Default: Double
+ ): Double;
+begin
+ Result := Default;
+ if not OpenKey(fPath+Section,false) then Exit;
+ try
+ if ValueExists(Ident) then
+ if (not fPreferStringValues) or (GetDataType(Ident)<>rdString) then
+ Result := inherited ReadFloat(Ident)
+ else
+ Result := StrToFloat(inherited ReadString(Ident));
+ finally
+ CloseKey;
+ end;
+end;
+
function TRegIniFile.ReadInteger(const Section, Ident: string; Default: LongInt): LongInt;
begin
Result := Default;
Index: registry.pp
===================================================================
--- registry.pp (revision 22046)
+++ registry.pp (working copy)
@@ -128,6 +128,9 @@
{ ---------------------------------------------------------------------
TRegIniFile
---------------------------------------------------------------------}
+
+ { TRegIniFile }
+
TRegIniFile = class(TRegistry)
private
fFileName : String;
@@ -140,10 +143,18 @@
function ReadInteger(const Section, Ident: string;
Default: Longint): Longint;
function ReadBool(const Section, Ident: string; Default: Boolean): Boolean;
+ function ReadDate(const Section, Ident: string; Default: TDateTime):TDateTime;
+ function ReadDateTime(const Section, Ident: string; Default: TDateTime):TDateTime;
+ function ReadTime(const Section, Ident: string; Default: TDateTime):TDateTime;
+ function ReadFloat(const Section, Ident: string; Default: Double): Double;
procedure WriteString(const Section, Ident, Value: String);
procedure WriteInteger(const Section, Ident: string; Value: Longint);
procedure WriteBool(const Section, Ident: string; Value: Boolean);
+ procedure WriteDate(const Section, Ident: string; Value: TDateTime);
+ procedure WriteDateTime(const Section, Ident: string; Value: TDateTime);
+ procedure WriteTime(const Section, Ident: string; Value: TDateTime);
+ procedure WriteFloat(const Section, Ident: string; Value: Double);
procedure ReadSection(const Section: string; Strings: TStrings);
procedure ReadSections(Strings: TStrings);
procedure ReadSectionValues(const Section: string; Strings: TStrings);
@@ -336,10 +347,6 @@
end;
function TRegistry.ReadCurrency(const Name: string): Currency;
-
-Var
- RegDataType: TRegDataType;
-
begin
ReadBinaryData(Name, Result, SizeOf(Currency));
end;
@@ -352,9 +359,6 @@
end;
function TRegistry.ReadDateTime(const Name: string): TDateTime;
-Var
- RegDataType: TRegDataType;
-
begin
ReadBinaryData(Name, Result, SizeOf(TDateTime));
end;
@@ -493,118 +497,26 @@
function TRegistryIniFile.ReadDate(const Section, Name: string;
Default: TDateTime): TDateTime;
-var sectkey,curkey : HKey;
-begin
- with FRegInifile do
- begin
- sectkey:=getkey(Section);
- if sectkey<>0 then
- begin
- try // allocation ok
- curkey:=FRegIniFile.CurrentKey;
- SetCurrentKey(sectKey);
- try // save current key
- if ValueExists(Name) THen
- result:=FRegIniFile.ReadDate(Name)
- else
- result:=default;
- finally
- SetCurrentKey(CurKey);
- end;
- finally
- closekey(sectkey);
- end;
- end
- else
- result:=default;
- end;
+begin
+ Result := FRegIniFile.ReadDate(Section,Name,Default);
end;
function TRegistryIniFile.ReadDateTime(const Section, Name: string;
Default: TDateTime): TDateTime;
-var sectkey,curkey : HKey;
begin
- with FRegInifile do
- begin
- sectkey:=getkey(Section);
- if sectkey<>0 then
- begin
- try // allocation ok
- curkey:=FRegIniFile.CurrentKey;
- SetCurrentKey(sectKey);
- try // save current key
- if ValueExists(Name) THen
- result:=FRegIniFile.ReadDateTime(Name)
- else
- result:=default;
- finally
- SetCurrentKey(CurKey);
- end;
- finally
- closekey(sectkey);
- end;
- end
- else
- result:=default;
- end;
+ Result := FRegIniFile.ReadDateTime(Section,Name,Default);
end;
function TRegistryIniFile.ReadFloat(const Section, Name: string;
Default: Double): Double;
-var sectkey,curkey : HKey;
begin
- with FRegInifile do
- begin
- sectkey:=getkey(Section);
- if sectkey<>0 then
- begin
- try // allocation ok
- curkey:=FRegIniFile.CurrentKey;
- SetCurrentKey(sectKey);
- try // save current key
- if ValueExists(Name) THen
- result:=FRegIniFile.ReadFloat(Name)
- else
- result:=default;
- finally
- SetCurrentKey(CurKey);
- end;
- finally
- closekey(sectkey);
- end;
- end
- else
- result:=default;
- end;
+ Result := FRegIniFile.ReadFloat(Section,Name,Default);
end;
function TRegistryIniFile.ReadInteger(const Section, Name: string;
Default: Integer): Longint;
-var sectkey,curkey : HKey;
begin
- with FRegInifile do
- begin
- sectkey:=getkey(Section);
- if sectkey<>0 then
- begin
- try // allocation ok
- curkey:=FRegIniFile.CurrentKey;
- SetCurrentKey(sectKey);
- try // save current key
- if ValueExists(Name) THen
- result:=FRegIniFile.ReadInteger(section,Name,default)
- else
- result:=default;
- finally
- SetCurrentKey(CurKey);
- end;
- finally
- closekey(sectkey);
- end;
- end
- else
- result:=default;
- end;
+ Result := FRegIniFile.ReadInteger(Section, Name, Default);
end;
procedure TRegistryIniFile.ReadSection(const Section: string;
@@ -626,60 +538,14 @@
function TRegistryIniFile.ReadString(const Section, Name,
Default: string): string;
-var sectkey,curkey : HKey;
begin
- with FRegInifile do
- begin
- sectkey:=getkey(Section);
- if sectkey<>0 then
- begin
- try // allocation ok
- curkey:=FRegIniFile.CurrentKey;
- SetCurrentKey(sectKey);
- try // save current key
- if ValueExists(Name) THen
- result:=FRegIniFile.ReadString(section,Name,default)
- else
- result:=default;
- finally
- SetCurrentKey(CurKey);
- end;
- finally
- closekey(sectkey);
- end;
- end
- else
- result:=default;
- end;
+ Result := FRegIniFile.ReadString(Section,Name,Default);
end;
function TRegistryIniFile.ReadTime(const Section, Name: string;
Default: TDateTime): TDateTime;
-var sectkey,curkey : HKey;
begin
- with FRegInifile do
- begin
- sectkey:=getkey(Section);
- if sectkey<>0 then
- begin
- try // allocation ok
- curkey:=FRegIniFile.CurrentKey;
- SetCurrentKey(sectKey);
- try // save current key
- if ValueExists(Name) THen
- result:=FRegIniFile.ReadTime(Name)
- else
- result:=default;
- finally
- SetCurrentKey(CurKey);
- end;
- finally
- closekey(sectkey);
- end;
- end
- else
- result:=default;
- end;
+ Result := FRegIniFile.ReadTime(Section,Name,Default);
end;
procedure TRegistryIniFile.UpdateFile;
@@ -695,146 +561,37 @@
procedure TRegistryIniFile.WriteDate(const Section, Name: string;
Value: TDateTime);
-var sectkey,curkey : HKey;
begin
- with FRegInifile do
- begin
- sectkey:=getkey(Section);
- if sectkey<>0 then
- begin
- try // allocation ok
- curkey:=FRegIniFile.CurrentKey;
- SetCurrentKey(sectKey);
- try // save current key
- FRegIniFile.WriteDate(name,value)
- finally
- SetCurrentKey(CurKey);
- end;
- finally
- closekey(sectkey);
- end;
- end
- end;
+ FRegIniFile.WriteDate(Section, Name, Value);
end;
procedure TRegistryIniFile.WriteDateTime(const Section, Name: string;
Value: TDateTime);
-var sectkey,curkey : HKey;
begin
- with FRegInifile do
- begin
- sectkey:=getkey(Section);
- if sectkey<>0 then
- begin
- try // allocation ok
- curkey:=FRegIniFile.CurrentKey;
- SetCurrentKey(sectKey);
- try // save current key
- FRegIniFile.WriteDateTime(Name,value)
- finally
- SetCurrentKey(CurKey);
- end;
- finally
- closekey(sectkey);
- end;
- end
- end;
+ FRegIniFile.WriteDateTime(Section, Name, Value);
end;
procedure TRegistryIniFile.WriteFloat(const Section, Name: string;
Value: Double);
-var sectkey,curkey : HKey;
begin
- with FRegInifile do
- begin
- sectkey:=getkey(Section);
- if sectkey<>0 then
- begin
- try // allocation ok
- curkey:=FRegIniFile.CurrentKey;
- SetCurrentKey(sectKey);
- try // save current key
- FRegIniFile.WriteFloat(Name,value)
- finally
- SetCurrentKey(CurKey);
- end;
- finally
- closekey(sectkey);
- end;
- end
- end;
+ FRegIniFile.WriteFloat(Section, Name, Value);
end;
procedure TRegistryIniFile.WriteInteger(const Section, Name: string;
Value: Integer);
-var sectkey,curkey : HKey;
begin
- with FRegInifile do
- begin
- sectkey:=getkey(Section);
- if sectkey<>0 then
- begin
- try // allocation ok
- curkey:=FRegIniFile.CurrentKey;
- SetCurrentKey(sectKey);
- try // save current key
- FRegIniFile.WriteInteger(section,Name,value)
- finally
- SetCurrentKey(CurKey);
- end;
- finally
- closekey(sectkey);
- end;
- end
- end;
-
+ FRegIniFile.WriteInteger(Section,Name,Value);
end;
procedure TRegistryIniFile.WriteString(const Section, Name, Value: String);
-var sectkey,curkey : HKey;
begin
- with FRegInifile do
- begin
- sectkey:=getkey(Section);
- if sectkey<>0 then
- begin
- try // allocation ok
- curkey:=FRegIniFile.CurrentKey;
- SetCurrentKey(sectKey);
- try // save current key
- FRegIniFile.WriteString(section,Name,value)
- finally
- SetCurrentKey(CurKey);
- end;
- finally
- closekey(sectkey);
- end;
- end
- end;
+ FRegIniFile.WriteString(Section,Name,Value);
end;
procedure TRegistryIniFile.WriteTime(const Section, Name: string;
Value: TDateTime);
-var sectkey,curkey : HKey;
begin
- with FRegInifile do
- begin
- sectkey:=getkey(Section);
- if sectkey<>0 then
- begin
- try // allocation ok
- curkey:=FRegIniFile.CurrentKey;
- SetCurrentKey(sectKey);
- try // save current key
- FRegIniFile.WriteTime(Name,value)
- finally
- SetCurrentKey(CurKey);
- end;
- finally
- closekey(sectkey);
- end;
- end
- end;
+ FRegIniFile.WriteTime(Section,Name,Value);
end;
end.
|