unit Common.Ini;

interface

uses
  System.SysUtils, System.IniFiles, Vcl.Forms;

type
  TIniEntries = class
  private
    // [Settings]
    FMemoLogLevel: Integer;
    FFileLogLevel: Integer;
    FLogFileNum: Integer;

    // [Database]
    FDBServer: string;
    FDBPort: Integer;
    FDBDatabase: string;
    FDBUsername: string;
    FDBPassword: string;

  public
    constructor Create;

    // Properties
    property memoLogLevel: Integer read FMemoLogLevel;
    property fileLogLevel: Integer read FFileLogLevel;
    property logFileNum: Integer read FLogFileNum;

    property dbServer: string read FDBServer;
    property dbPort: Integer read FDBPort;
    property dbDatabase: string read FDBDatabase;
    property dbUsername: string read FDBUsername;
    property dbPassword: string read FDBPassword;
  end;

  procedure LoadIniEntries;

var
  IniEntries: TIniEntries;

implementation

uses
  Common.Logging;


procedure LoadIniEntries;
begin
  Logger.Log(1, 'IniEntries global variable instantiated');
end;

{ TIniEntries }

constructor TIniEntries.Create;
var
  iniFile: TIniFile;
begin
  iniFile := TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini'));
  try
    // [Settings]
    FMemoLogLevel := iniFile.ReadInteger('Settings', 'MemoLogLevel', 3);
    FFileLogLevel := iniFile.ReadInteger('Settings', 'FileLogLevel', 3);
    FLogFileNum := iniFile.ReadInteger('Settings', 'LogFileNum', 0);
    Inc(FLogFileNum);
    iniFile.WriteInteger( 'Settings', 'LogFileNum', FLogFileNum );

    // [Database]
    FDBServer := iniFile.ReadString('Database', 'Server', '');
    FDBPort := iniFile.ReadInteger('Database', 'Port', 0);
    FDBDatabase := iniFile.ReadString('Database', 'Database', 'kg_order_entry');
    FDBUsername := iniFile.ReadString('Database', 'Username', 'root');
    FDBPassword := iniFile.ReadString('Database', 'Password', 'emsys01');
  finally
    iniFile.Free;
  end;
end;

initialization
  IniEntries := TIniEntries.Create;

finalization
  IniEntries.Free;


end.

