unit UdmMain;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  IB_Components, IB_Samples, IB_Process, IB_Script;

type
  TdmMain = class(TDataModule)
    scrMakeDB: TIB_Script;
    cn: TIB_Connection;
    procedure dmMainCreate(Sender: TObject);
    procedure scrMakeDBMacroSubstitute(Sender: TComponent;
      const ATextBlock: String; var ATextResult: String);
    procedure cnAfterConnect(Sender: TIB_Connection);
  private
    { Private declarations }
  public
    { Public declarations }
  end;


var
  dmMain: TdmMain;

implementation


{$R *.DFM}

procedure TdmMain.dmMainCreate(Sender: TObject);
begin
  ReadDefaultPath(cn,'TESTTransactionsHandlingPath');




  // Check if database file exists, if not create it,
  // if so, connect to it and open it
  cn.Connected := false;
  if fileexists(cn.Database) then begin
    cn.LoginPrompt := False;
  end
  else begin
    scrMakeDb.Execute;
  end;

end;

procedure TdmMain.scrMakeDBMacroSubstitute(Sender: TComponent;
  const ATextBlock: String; var ATextResult: String);
begin
  DefaultMacroSubstitute(ATextBlock, ATextResult);
end;

procedure TdmMain.cnAfterConnect(Sender: TIB_Connection);
begin
  WriteDefaultPath;
end;

end.
