Closed fabioxgn closed 8 years ago
I would ajust you're code some bit!
function ReadStringRegistryValue(const Value: string; const Default: string = ''): string;
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_CURRENT_USER;
if Reg.OpenKey(INTERNET_SETTINGS, false) and
Reg.ValueExists(Value) then
Result := Reg.ReadString(Value)
else
Result := Default;
finally
Reg.Free;
end;
end;
function ReadIntegerRegistryValue(const Value: string; const Default: Integer = 0): Integer;
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_CURRENT_USER;
if Reg.OpenKey(INTERNET_SETTINGS, false) and
Reg.ValueExists(Value) then
Result := Reg.ReadInteger(Value)
else
Result := Default;
finally
Reg.Free;
end;
end;
@ronaldhoek did some changes to remove the exception handling using OpenKeyReadOnly
. Also both functions already return a default, empty string or 0 and as it is used just in this unit, this is enough IMO.
@fabioxgn You're right, no need for the defaults!
This ERegistryException is handled but it shows up in our logs, also it is not a good idea to use exceptions flow control.