Added: ValueExists method
Fixed: Registry check if value exists to prevent unneccesary exceptions
This commit is contained in:
parent
3f8b9fc77b
commit
c90841f23e
@ -60,6 +60,8 @@ type
|
|||||||
procedure WriteInteger(const AName: String; AValue: Integer); virtual; abstract;
|
procedure WriteInteger(const AName: String; AValue: Integer); virtual; abstract;
|
||||||
procedure WriteString(const AName, AValue: String); virtual; abstract;
|
procedure WriteString(const AName, AValue: String); virtual; abstract;
|
||||||
|
|
||||||
|
function ValueExists(const AName: String): Boolean; virtual; abstract;
|
||||||
|
|
||||||
procedure GetSectionNames(const ADest: TStrings); virtual; abstract;
|
procedure GetSectionNames(const ADest: TStrings); virtual; abstract;
|
||||||
procedure GetValueNames(const ADest: TStrings); virtual; abstract;
|
procedure GetValueNames(const ADest: TStrings); virtual; abstract;
|
||||||
|
|
||||||
|
@ -65,6 +65,8 @@ type
|
|||||||
procedure WriteInteger(const AName: String; AValue: Integer); override;
|
procedure WriteInteger(const AName: String; AValue: Integer); override;
|
||||||
procedure WriteString(const AName, AValue: String); override;
|
procedure WriteString(const AName, AValue: String); override;
|
||||||
|
|
||||||
|
function ValueExists(const AName: String): Boolean; override;
|
||||||
|
|
||||||
procedure GetSectionNames(const ADest: TStrings); override;
|
procedure GetSectionNames(const ADest: TStrings); override;
|
||||||
procedure GetValueNames(const ADest: TStrings); override;
|
procedure GetValueNames(const ADest: TStrings); override;
|
||||||
|
|
||||||
@ -174,6 +176,12 @@ end;
|
|||||||
{========================= TX2INISettings
|
{========================= TX2INISettings
|
||||||
Enumeration
|
Enumeration
|
||||||
========================================}
|
========================================}
|
||||||
|
function TX2INISettings.ValueExists;
|
||||||
|
begin
|
||||||
|
Result := FData.ValueExists(FSection, AName);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TX2INISettings.GetSectionNames;
|
procedure TX2INISettings.GetSectionNames;
|
||||||
var
|
var
|
||||||
slSections: TStringList;
|
slSections: TStringList;
|
||||||
|
@ -71,6 +71,8 @@ type
|
|||||||
procedure WriteInteger(const AName: String; AValue: Integer); override;
|
procedure WriteInteger(const AName: String; AValue: Integer); override;
|
||||||
procedure WriteString(const AName, AValue: String); override;
|
procedure WriteString(const AName, AValue: String); override;
|
||||||
|
|
||||||
|
function ValueExists(const AName: String): Boolean; override;
|
||||||
|
|
||||||
procedure GetSectionNames(const ADest: TStrings); override;
|
procedure GetSectionNames(const ADest: TStrings); override;
|
||||||
procedure GetValueNames(const ADest: TStrings); override;
|
procedure GetValueNames(const ADest: TStrings); override;
|
||||||
|
|
||||||
@ -169,50 +171,48 @@ end;
|
|||||||
========================================}
|
========================================}
|
||||||
function TX2RegistrySettings.ReadBool;
|
function TX2RegistrySettings.ReadBool;
|
||||||
begin
|
begin
|
||||||
if OpenRead() then
|
Result := ADefault;
|
||||||
|
|
||||||
|
if (OpenRead()) and (FData.ValueExists(AName)) then
|
||||||
try
|
try
|
||||||
Result := FData.ReadBool(AName)
|
Result := FData.ReadBool(AName)
|
||||||
except
|
except
|
||||||
Result := ADefault;
|
// Silently ignore exceptions so the
|
||||||
end
|
// default value gets returned
|
||||||
else
|
end;
|
||||||
Result := ADefault;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TX2RegistrySettings.ReadFloat;
|
function TX2RegistrySettings.ReadFloat;
|
||||||
begin
|
begin
|
||||||
if OpenRead() then
|
Result := ADefault;
|
||||||
|
|
||||||
|
if (OpenRead()) and (FData.ValueExists(AName)) then
|
||||||
try
|
try
|
||||||
Result := FData.ReadFloat(AName)
|
Result := FData.ReadFloat(AName)
|
||||||
except
|
except
|
||||||
Result := ADefault;
|
end;
|
||||||
end
|
|
||||||
else
|
|
||||||
Result := ADefault;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TX2RegistrySettings.ReadInteger;
|
function TX2RegistrySettings.ReadInteger;
|
||||||
begin
|
begin
|
||||||
if OpenRead() then
|
Result := ADefault;
|
||||||
|
|
||||||
|
if (OpenRead()) and (FData.ValueExists(AName)) then
|
||||||
try
|
try
|
||||||
Result := FData.ReadInteger(AName)
|
Result := FData.ReadInteger(AName)
|
||||||
except
|
except
|
||||||
Result := ADefault;
|
end;
|
||||||
end
|
|
||||||
else
|
|
||||||
Result := ADefault;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TX2RegistrySettings.ReadString;
|
function TX2RegistrySettings.ReadString;
|
||||||
begin
|
begin
|
||||||
if OpenRead() then
|
Result := ADefault;
|
||||||
|
|
||||||
|
if (OpenRead()) and (FData.ValueExists(AName)) then
|
||||||
try
|
try
|
||||||
Result := FData.ReadString(AName)
|
Result := FData.ReadString(AName)
|
||||||
except
|
except
|
||||||
Result := ADefault;
|
end;
|
||||||
end
|
|
||||||
else
|
|
||||||
Result := ADefault;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -253,6 +253,7 @@ begin
|
|||||||
FData.GetKeyNames(ADest);
|
FData.GetKeyNames(ADest);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TX2RegistrySettings.GetValueNames;
|
procedure TX2RegistrySettings.GetValueNames;
|
||||||
begin
|
begin
|
||||||
if OpenRead() then
|
if OpenRead() then
|
||||||
@ -280,4 +281,10 @@ begin
|
|||||||
FData.DeleteValue(AName);
|
FData.DeleteValue(AName);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TX2RegistrySettings.ValueExists;
|
||||||
|
begin
|
||||||
|
if OpenRead() then
|
||||||
|
Result := FData.ValueExists(AName);
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user