Skip to content

Commit

Permalink
implement read boolean value
Browse files Browse the repository at this point in the history
  • Loading branch information
zamronypj committed Sep 4, 2019
1 parent 9540736 commit 5aa033a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Config/Contracts/ConfigIntf.pas
Expand Up @@ -15,6 +15,7 @@ interface
['{054EE7FE-20CF-4E46-A9B2-37921D890E33}']
function getString(const configName : string; const defaultValue : string = '') : string;
function getInt(const configName : string; const defaultValue : integer = 0) : integer;
function getBool(const configName : string; const defaultValue : boolean = false) : boolean;
end;

implementation
Expand Down
14 changes: 14 additions & 0 deletions src/Config/JsonConfigImpl.pas
Expand Up @@ -35,6 +35,7 @@ TJsonConfig = class(TInterfacedObject, IAppConfiguration, IDependency)
destructor destroy(); override;
function getString(const configName : string; const defaultValue : string = '') : string;
function getInt(const configName : string; const defaultValue : integer = 0) : integer;
function getBool(const configName : string; const defaultValue : boolean = false) : boolean;
end;

implementation
Expand Down Expand Up @@ -80,4 +81,17 @@ implementation
end;
end;

function TJsonConfig.getBool(const configName : string; const defaultValue : boolean = false) : boolean;
var jsonData : TJSONData;
begin
jsonData := json.findPath(configName);
if (jsonData = nil) then
begin
result := defaultValue;
end else
begin
result := jsonData.asBoolean;
end;
end;

end.

0 comments on commit 5aa033a

Please sign in to comment.