fabriciocolombo / delphi-rest-client-api

A Delphi REST client API to consume REST services written in any programming language.
Apache License 2.0
380 stars 182 forks source link

Check if proxy values exists before reading from registry #70

Closed fabioxgn closed 8 years ago

fabioxgn commented 8 years ago

This ERegistryException is handled but it shows up in our logs, also it is not a good idea to use exceptions flow control.

ronaldhoek commented 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;
fabioxgn commented 8 years ago

@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.

ronaldhoek commented 8 years ago

@fabioxgn You're right, no need for the defaults!