Tecsitel_FactuGES2/Source/Base/Configuracion/uDataModuleConfiguracion.pas

94 lines
2.2 KiB
ObjectPascal

unit uDataModuleConfiguracion;
interface
uses
SysUtils, Classes, uRORemoteService, uDADataTable,
uDABINAdapter, uROClient, IniFiles,
uDADataStreamer;
type
TdmConfiguracion = class(TDataModule)
RORemoteService: TRORemoteService;
private
FIniFile : TIniFile;
public
function DarValor(const CODIGO: String; const ValorPorDefecto: 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,
uSistemaFunc, SHFolder, uAppInfoUtils;
const
CONFIG_INI_FILE = 'config.ini';
{ TdmConfiguracion }
constructor TdmConfiguracion.Create(AOwner: TComponent);
var
AIniFile : String;
begin
inherited;
AIniFile := GetSpecialFolderPath(CSIDL_COMMON_APPDATA); //[All Users]\Application Data
AIniFile := AIniFile + PathDelim + GetAppName + PathDelim;
if not DirectoryExists(AIniFile) then
CreateDir(AIniFile);
FIniFile := TIniFile.Create(AIniFile + CONFIG_INI_FILE);
end;
function TdmConfiguracion.DarValor(const CODIGO: String; const ValorPorDefecto: String = ''): Variant;
begin
RORemoteService.Channel := dmConexion.ROChannel;
RORemoteService.Message := dmConexion.ROMessage;
Result := (RORemoteService as IsrvConfiguracion).DarValor(CODIGO, ValorPorDefecto);
end;
destructor TdmConfiguracion.Destroy;
begin
FreeAndNIL(FIniFile);
inherited;
end;
procedure TdmConfiguracion.LeerConfiguracion;
var
AStream : TMemoryStream;
begin
AStream := TMemoryStream.Create();
try
if (FIniFile.ReadBinaryStream('Server', 'URLs', AStream) > 0) then
dmConexion.ListaConexiones.LoadFromStream(AStream);
finally
FreeAndNIL(AStream);
end;
end;
procedure TdmConfiguracion.SalvarConfiguracion;
var
AStream : TMemoryStream;
begin
AStream := TMemoryStream.Create();
try
dmConexion.ListaConexiones.SaveToStream(AStream);
AStream.Position := 0;
FIniFile.WriteBinaryStream('Server', 'URLs', AStream);
finally
FreeAndNil(AStream);
end;
end;
end.