unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, DB, ShellApi, FIBDataSet, pFIBDataSet, Menus,
  FIBDatabase, pFIBDatabase, ComCtrls, Wwintl, ImgList, pFIBScripter,
  wwdbdatetimepicker;

type
  TForm1 = class(TForm)
    IBDatabase1: TpFIBDatabase;
    trTrans: TpFIBTransaction;
    IBQuery1: TpFIBDataSet;
    Panel1: TPanel;
    Label5: TLabel;
    Panel2: TPanel;
    StatusBar1: TStatusBar;
    GroupBox1: TGroupBox;
    wwIntl1: TwwIntl;
    GroupBox4: TGroupBox;
    Button3: TButton;
    Scripter1: TpFIBScripter;
    Label2: TLabel;
    Label3: TLabel;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
  Procedure Cerrar_la_aplicacion();
  end;

var
  Form1: TForm1;

implementation

uses Unit101;


{$R *.dfm}

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Cerrar_la_aplicacion();
end;

Procedure TForm1.Cerrar_la_aplicacion();
begin
  if MessageDlg('¿Esta seguro que desea salir de la aplicación?',
    mtConfirmation, [mbYes, mbNo], 0, mbYes) = mrYes then
  begin
    trTrans.Active := false;
    IBDatabase1.Connected := False;
    Application.Terminate;
  end
  else Abort;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  {$REGION 'VERSION 1'}
  try
  begin
      if trTrans.InTransaction then
        trTrans.Rollback;
      trTrans.StartTransaction;

      Scripter1.ExecuteScript(1);

      if trTrans.InTransaction then
        trTrans.Commit;
      MessageDlg('Se eliminó correctamente el procedimiento', mtInformation, [mbOk], 0);
  end
  except on e:Exception do
  begin
   if trTrans.InTransaction then
      trTrans.Rollback;
    MessageDlg('Error al eliminar el procedimiento. ', mtError, [mbOk], 0);
    exit;
  end;
  end;
  {$ENDREGION}
end;

end.
