{
**************************** !!!  !!! *****************************
            
     .
       "Tools\Debugger Options", 
"Language Exceptions".  "Stop On Delphi Exceptions"  .
***************************************************************************
}
unit fmuMain;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComObj;

type
  TfrmMain = class(TForm)
    btnStart: TButton;
    btnShowProperties: TButton;
    procedure btnShowPropertiesClick(Sender: TObject);
    procedure btnStartClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmMain: TfrmMain;
  ECR: OleVariant;

implementation

{$R *.DFM}

procedure Demo;
begin
//  
  ECR.DeviceEnabled := true;
  if ECR.ResultCode <> 0 then Exit;

//   
  if ECR.GetStatus <> 0 then Exit;

//       
  if ECR.Fiscal then
    if Application.MessageBox(' !    ?', PChar(Application.Title), MB_ICONEXCLAMATION + MB_YESNO) = idNo then
      Exit;

//    ,   
  if ECR.CheckState <> 0 then
    if ECR.CancelCheck <> 0 then Exit;

//     Z-
  if ECR.SessionOpened then
  begin
    //     
    ECR.Password := '30';
    //      
    ECR.Mode := 3;
    if ECR.SetMode <> 0 then Exit;
    //  
    ECR.ReportType := 1;
    if ECR.Report <> 0 then Exit;
  end;

//    
  //   
  ECR.Password := '1';
  //    
  ECR.Mode := 1;
  if ECR.SetMode <> 0 then Exit;

//   
  //  
  ECR.Name := '';
  ECR.Price := 10.45;
  ECR.Quantity := 1;
  ECR.Department := 2;
  if ECR.Registration <> 0 then Exit;
  //     
  ECR.Percents := 10;
  ECR.Destination := 1;
  if ECR.PercentsDiscount <> 0 then Exit;
  //  
  ECR.Name := '';
  ECR.Price := 25;
  ECR.Quantity := 5;
  ECR.Department := 1;
  if ECR.Registration <> 0 then Exit;
  //     
  ECR.Summ := 10.40;
  ECR.Destination := 0;
  if ECR.SummDiscount <> 0 then Exit;
  //         
  ECR.TypeClose := 0;
  if ECR.CloseCheck <> 0 then Exit;

//   
  //  
  ECR.Name := '';
  ECR.Price := 10.45;
  ECR.Quantity := 1;
  ECR.Department := 2;
  if ECR.Registration <> 0 then Exit;
  //  
  ECR.Name := '-';
  ECR.Price := 25.00;
  ECR.Quantity := 5;
  ECR.Department := 1;
  if ECR.Registration <> 0 then Exit;
  //   
  if ECR.Storno <> 0 then Exit;
  //  
  ECR.Name := '';
  ECR.Price := 25;
  ECR.Quantity := 5;
  ECR.Department := 1;
  if ECR.Registration <> 0 then Exit;
  //     
  ECR.Summ := 50;
  ECR.Destination := 0;
  if ECR.SummDiscount <> 0 then Exit;
  //         
  ECR.Summ := 100;
  ECR.TypeClose := 0;
  if ECR.Delivery <> 0 then Exit;

// 
  //  
  ECR.Name := 'Dirol';
  ECR.Price := 7;
  ECR.Quantity := 1;
  if ECR.Annulate <> 0 then Exit;
  //  
  ECR.Name := 'Orbit';
  ECR.Price := 8;
  ECR.Quantity := 2;
  if ECR.Annulate <> 0 then Exit;
  //  
  ECR.TypeClose := 0;
  if ECR.CloseCheck <> 0 then Exit;

// 
  //  
  ECR.Name := '';
  ECR.Price := 10.45;
  ECR.Quantity := 1;
  if ECR.Return <> 0 then Exit;
  //  
  ECR.Name := '';
  ECR.Price := 99.99;
  ECR.Quantity := 1.235;
  if ECR.Return <> 0 then Exit;
  //     
  ECR.Summ := 50;
  ECR.Destination := 0;
  if ECR.SummDiscount <> 0 then Exit;
  //  
  ECR.TypeClose := 0;
  if ECR.CloseCheck <> 0 then Exit;

//  
  ECR.Summ := 400.50;
  if ECR.CashIncome <> 0 then Exit;

//  
  ECR.Summ := 121.34;
  if ECR.CashOutcome <> 0 then Exit;

// X - 
  //    
  ECR.Password := '29';
  //      
  ECR.Mode := 2;
  if ECR.SetMode <> 0 then Exit;
  //  
  ECR.ReportType := 2;
  if ECR.Report <> 0 then Exit;

// Z - 
  //     
  ECR.Password := '30';
  //      
  ECR.Mode := 3;
  if ECR.SetMode <> 0 then Exit;
  //  
  ECR.ReportType := 1;
  if ECR.Report <> 0 then Exit;

//    ,  -        
  if ECR.ResetMode <> 0 then Exit;

//  
  ECR.DeviceEnabled := false;
  if ECR.ResultCode <> 0 then Exit;

  Application.MessageBox('   .', PChar(Application.title), MB_ICONINFORMATION + MB_OK);
end;

procedure TfrmMain.btnStartClick(Sender: TObject);
begin
  btnStart.Enabled := false;
  btnShowProperties.Enabled := false;

  Demo;
  if ECR.ResultCode <> 0 then
    Application.MessageBox(PChar(' : ' + string(ECR.ResultDescription) + '!'), PChar(Application.Title), MB_ICONERROR + MB_OK);

  btnStart.Enabled := true;
  btnShowProperties.Enabled := true;
end;

procedure TfrmMain.btnShowPropertiesClick(Sender: TObject);
begin
//   
  ECR.ShowProperties;
end;

procedure TfrmMain.FormShow(Sender: TObject);
begin
//     
//       ,     
  try
    ECR := CreateOleObject('AddIn.FprnM45');
    ECR.ApplicationHandle := Application.Handle; //         
  except
    Application.MessageBox('      !', PChar(Application.Title), MB_ICONERROR + MB_OK);
    Application.Terminate;
  end;
end;

procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
//   
  ECR := 0;
end;

end.
