unit mainfrm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, nrclasses, nrcommtapi, nrwave, nrcommbox, nrcomm,
  ComCtrls, nrwavebase, nrlogfile;

type
  TForm1 = class(TForm)
    nrCommTAPI1: TnrCommTAPI;
    nrDeviceBox1: TnrDeviceBox;
    nrWave1: TnrWave;
    Label1: TLabel;
    Button1: TButton;
    GroupBox1: TGroupBox;
    CheckBox1: TCheckBox;
    Edit2: TEdit;
    Label2: TLabel;
    Label3: TLabel;
    Button2: TButton;
    StatusBar1: TStatusBar;
    GroupBox2: TGroupBox;
    Edit1: TEdit;
    Label4: TLabel;
    Button3: TButton;
    ListBox1: TListBox;
    Label5: TLabel;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Edit3: TEdit;
    Edit4: TEdit;
    eRecDir: TComboBox;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure nrCommTAPI1DTMF(Com: TObject; Digit: Char);
    procedure CheckBox1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure nrCommTAPI1FatalError(Sender: TObject; ErrorCode,
      Detail: Cardinal; ErrorMsg: String; var RaiseException: Boolean);
    procedure Button6Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure nrWave1AfterPlay(Sender: TObject);
    procedure nrWave1AfterRecord(Sender: TObject);
    procedure nrCommTAPI1LineConnected(Sender: TObject);
    procedure nrCommTAPI1LineDisconnected(Com: TObject; ByRemote: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  nrCommTAPI1.DeviceConfigDialog;
end;

procedure TForm1.nrCommTAPI1DTMF(Com: TObject; Digit: Char);
begin
  ListBox1.Items.Add('DTMF Detected: '+Digit);
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  nrCommTAPI1.Voice:=True;
  if CheckBox1.Checked then begin
    try
      nrCommTAPI1.RingsBeforeAnswer:=StrToInt(Edit2.Text);
    except
      nrCommTAPI1.RingsBeforeAnswer:=2;
    end;
    nrCommTAPI1.WaitForIncomingCall;
  end else nrCommTAPI1.HangUp;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  nrCommTAPI1.HangUp;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  nrCommTAPI1.Phone:=Edit1.Text;
  nrCommTAPI1.Voice:=True;
//  nrCommTAPI1.Pulse:=True;
  nrCommTAPI1.Call;
end;

procedure TForm1.nrCommTAPI1FatalError(Sender: TObject; ErrorCode,
  Detail: Cardinal; ErrorMsg: String; var RaiseException: Boolean);
begin
  ListBox1.Items.Add('Fatal Error: '+ErrorMsg);
  RaiseException:=False;
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
  nrWave1.PlayStop;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  nrWave1.PlayFileName:=Edit3.Text;
  nrWave1.PlayStart;
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
  nrWave1.RecDest:=TWaveDirection(eRecDir.ItemIndex);//  wdUseFile;
  nrWave1.RecFileName:=Edit4.Text;
//  nrWave1.RecDSecBlock:=StrToInt(eDec.Text);
  nrWave1.RecordStart;
end;
                 
procedure TForm1.Button8Click(Sender: TObject);
begin                   
  nrWave1.RecordStop;
end;

procedure TForm1.nrWave1AfterPlay(Sender: TObject);
begin
  ListBox1.Items.Add('Play finished');
end;

procedure TForm1.nrWave1AfterRecord(Sender: TObject);
begin
  ListBox1.Items.Add('Record finished');
end;

procedure TForm1.nrCommTAPI1LineConnected(Sender: TObject);
begin
  ListBox1.Items.Add('Connection established');
  ListBox1.Items.Add('Welcome message is playing ...');
  Button5Click(Sender);
end;

procedure TForm1.nrCommTAPI1LineDisconnected(Com: TObject;
  ByRemote: Boolean);
begin
  ListBox1.Items.Add('Line disconnected');
end;

end.
