unit uFactuGES_App; interface uses SysUtils, Classes, Forms, uUsuarios, uBizEmpresas, uEmpresasController, JclFileUtils, uUsuariosController; type TAppFactuGES = class(TObject) private FAppInfo : TJclFileVersionInfo; FEmpresasController : IEmpresasController; FUsuariosController: IUsuariosController; FEmpresaActiva: IBizEmpresa; function GetAppForm: TCustomForm; function GetEmpresasController: IEmpresasController; function GetUsuariosController: IUsuariosController; function GetAppName: String; function GetAppVersion: String; function GetUsuarioActivo: TUsuario; protected procedure InitializeInstance; virtual; procedure DestroyInstance; virtual; public class function NewInstance: TObject; override; procedure FreeInstance; override; class function RefCount: Integer; procedure CambarEmpresa(const AIDEmpresa : Integer); property AppVersion : String read GetAppVersion; property AppName : String read GetAppName; property AppForm : TCustomForm read GetAppForm; property EmpresaActiva : IBizEmpresa read FEmpresaActiva; property UsuarioActivo : TUsuario read GetUsuarioActivo; property EmpresasController : IEmpresasController read GetEmpresasController; property UsuariosController : IUsuariosController read GetUsuariosController; end; var AppFactuGES : TAppFactuGES = nil; implementation uses uDataModuleBase, uUsuariosViewRegister, uEmpresasViewRegister; var Ref_Count : Integer = 0; procedure TAppFactuGES.CambarEmpresa(const AIDEmpresa: Integer); var Aux : IBizEmpresa; begin Aux := EmpresasController.Buscar(AIDEmpresa); if Assigned(Aux) then begin Aux.DataTable.Active := True; if not Aux.IsEmpty then FEmpresaActiva := Aux; end; end; procedure TAppFactuGES.DestroyInstance; begin FreeAndNIL(FAppInfo); end; procedure TAppFactuGES.FreeInstance; begin Dec(Ref_Count); if (Ref_Count = 0) then begin AppFactuGES := NIL; // Destroy private variables here DestroyInstance; inherited FreeInstance; end; end; function TAppFactuGES.GetAppForm: TCustomForm; begin Result := Application.MainForm; end; function TAppFactuGES.GetAppName: String; begin Result := FAppInfo.ProductName; end; function TAppFactuGES.GetAppVersion: String; begin Result := FAppInfo.ProductVersion; end; function TAppFactuGES.GetEmpresasController: IEmpresasController; begin Result := FEmpresasController; end; function TAppFactuGES.GetUsuarioActivo: TUsuario; begin Result := FUsuariosController.CurrentUser; end; function TAppFactuGES.GetUsuariosController: IUsuariosController; begin Result := FUsuariosController; end; procedure TAppFactuGES.InitializeInstance; begin FEmpresaActiva := NIL; FAppInfo := TJclFileVersionInfo.Create(Application.ExeName); FUsuariosController := TUsuariosController.Create; FEmpresasController := TEmpresasController.Create; end; class function TAppFactuGES.NewInstance: TObject; begin if (not Assigned(AppFactuGES)) then begin AppFactuGES := TAppFactuGES(inherited NewInstance); // Initialize private variables here AppFactuGES.InitializeInstance; end; Result := AppFactuGES; Inc(Ref_Count); end; class function TAppFactuGES.RefCount: Integer; begin Result := Ref_Count; end; initialization AppFactuGES := TAppFactuGES.Create; // Pongo esto aquí por ahora uUsuariosViewRegister.RegisterViews; uEmpresasViewRegister.RegisterViews; finalization FreeAndNIL(AppFactuGES); // Pongo esto aquí por ahora uUsuariosViewRegister.UnregisterViews; uEmpresasViewRegister.UnregisterViews; end.