unit uDataModuleConfiguracion;

interface

uses
  SysUtils, Classes, uROServiceComponent, uRORemoteService, uDADataTable,
  uDABINAdapter, uROClient, uROBinMessage, uROWinInetHttpChannel, IniFiles;

const
  SERVER_URL = 'http://localhost:8099/bin';

type
  TdmConfiguracion = class(TDataModule)
    ROChannel: TROWinInetHTTPChannel;
    ROMessage: TROBinMessage;
    DABINAdapter: TDABINAdapter;
    RORemoteService: TRORemoteService;
  private
    FIniFile : TIniFile;
  public
    function DarValor(const CODIGO: String): Variant;
    procedure LeerConfiguracion;
    procedure SalvarConfiguracion;
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  end;

var
  dmConfiguracion: TdmConfiguracion;

implementation

{$R *.dfm}

uses
  Forms, FactuGES_Intf, Variants, uDataModuleConexion;


{ TdmConfiguracion }

constructor TdmConfiguracion.Create(AOwner: TComponent);
begin
  inherited;
  FIniFile := TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini' ) );
end;

function TdmConfiguracion.DarValor(const CODIGO: String): Variant;
begin
  Result := (RORemoteService as IsrvConfiguracion).DarValor(CODIGO);
end;

destructor TdmConfiguracion.Destroy;
begin
  FreeAndNIL(FIniFile);
  inherited;
end;

procedure TdmConfiguracion.LeerConfiguracion;
begin
  with FIniFile do
    dmConexion.TargetURL := ReadString('Server', 'URL', SERVER_URL);
end;

procedure TdmConfiguracion.SalvarConfiguracion;
begin
  with FIniFile do
    WriteString('Server', 'URL', dmConexion.TargetURL);
end;

end.
