unit uBootStrap;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uSplash, uFactuGES_App, StdCtrls;

procedure Initialize;
procedure Run;
procedure Terminate;

implementation

uses
  uDMBase, uDataModuleConexion, uDataModuleConfiguracion, uPlugins_Intf,
  uMainMenuController, uNavPaneController, uPantallaPrincipal;

procedure DoAppLoadModules;
begin
  with AppFactuGES.ModuleManager do
  begin
    LoadModule('Referencias_plugin.bpl');  
    LoadModule('UnidadesMedida_plugin.bpl');
    LoadModule('Contactos_plugin.bpl');
    LoadModule('Medicaciones_plugin.bpl');
  end;
end;

procedure DoRefreshMainForm;
begin
  fPantallaPrincipal.RefrescarUI;
end;

procedure DoAppMainForm;
begin
  Application.CreateForm(TfPantallaPrincipal, fPantallaPrincipal);
end;

procedure Initialize;
begin
  dmConexion := TdmConexion.Create(NIL);
  dmConfiguracion := TdmConfiguracion.Create(NIL);
  dmBase := TdmBase.Create(NIL);

  AppFactuGES := TAppFactuGES.Create;
  with AppFactuGES do
  begin
    AppSplashForm := TAppSplashForm.Create;
    DoMainFormEvent := DoAppMainForm;
    DoLoadModulesEvent := DoAppLoadModules;
    DoRefreshMainFormEvent := DoRefreshMainForm; 
  end;

  NavPaneController := TNavPaneController.Create;
  MainMenuController := TMainMenuController.Create;
end;

procedure Run;
begin
  AppFactuGES.Run;
end;

procedure Terminate;
begin
  FreeANDNIL(MainMenuController);
  FreeANDNIL(NavPaneController);

  AppFactuGES := NIL;

  FreeANDNIL(dmBase);
  FreeANDNIL(dmConfiguracion);
  FreeAndNil(dmConexion);

  Application.ProcessMessages
end;

end.
