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 WriteString(const AName, AValue: String); virtual; abstract;
|
||||
|
||||
function ValueExists(const AName: String): Boolean; virtual; abstract;
|
||||
|
||||
procedure GetSectionNames(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 WriteString(const AName, AValue: String); override;
|
||||
|
||||
function ValueExists(const AName: String): Boolean; override;
|
||||
|
||||
procedure GetSectionNames(const ADest: TStrings); override;
|
||||
procedure GetValueNames(const ADest: TStrings); override;
|
||||
|
||||
@ -174,6 +176,12 @@ end;
|
||||
{========================= TX2INISettings
|
||||
Enumeration
|
||||
========================================}
|
||||
function TX2INISettings.ValueExists;
|
||||
begin
|
||||
Result := FData.ValueExists(FSection, AName);
|
||||
end;
|
||||
|
||||
|
||||
procedure TX2INISettings.GetSectionNames;
|
||||
var
|
||||
slSections: TStringList;
|
||||
|
@ -71,6 +71,8 @@ type
|
||||
procedure WriteInteger(const AName: String; AValue: Integer); override;
|
||||
procedure WriteString(const AName, AValue: String); override;
|
||||
|
||||
function ValueExists(const AName: String): Boolean; override;
|
||||
|
||||
procedure GetSectionNames(const ADest: TStrings); override;
|
||||
procedure GetValueNames(const ADest: TStrings); override;
|
||||
|
||||
@ -169,50 +171,48 @@ end;
|
||||
========================================}
|
||||
function TX2RegistrySettings.ReadBool;
|
||||
begin
|
||||
if OpenRead() then
|
||||
Result := ADefault;
|
||||
|
||||
if (OpenRead()) and (FData.ValueExists(AName)) then
|
||||
try
|
||||
Result := FData.ReadBool(AName)
|
||||
except
|
||||
Result := ADefault;
|
||||
end
|
||||
else
|
||||
Result := ADefault;
|
||||
// Silently ignore exceptions so the
|
||||
// default value gets returned
|
||||
end;
|
||||
end;
|
||||
|
||||
function TX2RegistrySettings.ReadFloat;
|
||||
begin
|
||||
if OpenRead() then
|
||||
Result := ADefault;
|
||||
|
||||
if (OpenRead()) and (FData.ValueExists(AName)) then
|
||||
try
|
||||
Result := FData.ReadFloat(AName)
|
||||
except
|
||||
Result := ADefault;
|
||||
end
|
||||
else
|
||||
Result := ADefault;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TX2RegistrySettings.ReadInteger;
|
||||
begin
|
||||
if OpenRead() then
|
||||
Result := ADefault;
|
||||
|
||||
if (OpenRead()) and (FData.ValueExists(AName)) then
|
||||
try
|
||||
Result := FData.ReadInteger(AName)
|
||||
except
|
||||
Result := ADefault;
|
||||
end
|
||||
else
|
||||
Result := ADefault;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TX2RegistrySettings.ReadString;
|
||||
begin
|
||||
if OpenRead() then
|
||||
Result := ADefault;
|
||||
|
||||
if (OpenRead()) and (FData.ValueExists(AName)) then
|
||||
try
|
||||
Result := FData.ReadString(AName)
|
||||
except
|
||||
Result := ADefault;
|
||||
end
|
||||
else
|
||||
Result := ADefault;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
@ -253,6 +253,7 @@ begin
|
||||
FData.GetKeyNames(ADest);
|
||||
end;
|
||||
|
||||
|
||||
procedure TX2RegistrySettings.GetValueNames;
|
||||
begin
|
||||
if OpenRead() then
|
||||
@ -280,4 +281,10 @@ begin
|
||||
FData.DeleteValue(AName);
|
||||
end;
|
||||
|
||||
function TX2RegistrySettings.ValueExists;
|
||||
begin
|
||||
if OpenRead() then
|
||||
Result := FData.ValueExists(AName);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user