main.pas
上传用户:xtonglei
上传日期:2019-08-12
资源大小:6118k
文件大小:37k
源码类别:

TAPI编程

开发平台:

C++ Builder

  1. {******************************************************************************}
  2. {*        Copyright 1999-2003 by J.Friebel all rights reserved.               *}
  3. {*        Autor           :  J鰎g Friebel                                     *}
  4. {*        Compiler        :  Delphi 7                                         *}
  5. {*        System          :  Windows XP / 2000                                *}
  6. {*        Projekt         :  TAPI Komponenten (TAPI Version 1.4 bis 3.0)      *}
  7. {*        Last Update     :  24.07.2003                                       *}
  8. {*        Version         :  3.3                                              *}
  9. {*        EMail           :  tapi@delphiclub.de                               *}
  10. {******************************************************************************}
  11. {*                                                                            *}
  12. {*    This File is free software; You can redistribute it and/or modify it    *}
  13. {*    under the term of GNU Library General Public License as published by    *}
  14. {*    the Free Software Foundation. This File is distribute in the hope       *}
  15. {*    it will be useful "as is", but WITHOUT ANY WARRANTY OF ANY KIND;        *}
  16. {*    See the GNU Library Public Licence for more details.                    *}
  17. {*                                                                            *}
  18. {******************************************************************************}
  19. {*                                                                            *}
  20. {*    Diese Datei ist Freie-Software. Sie k鰊nen sie weitervertreiben         *}
  21. {*    und/oder ver鋘dern im Sinne der Bestimmungen der "GNU Library GPL"      *}
  22. {*    der Free Software Foundation. Diese Datei wird,"wie sie ist",           *}
  23. {*    zur Verf黦ung gestellt, ohne irgendeine GEW腍RLEISTUNG                  *}
  24. {*                                                                            *}
  25. {******************************************************************************}
  26. {*                          www.delphiclub.de                                 *}
  27. {******************************************************************************}
  28. unit main;
  29. interface
  30. uses
  31.   mmsystem,Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
  32.   Forms, TAPICall, CallList, XPMan, TAPITon, TAPIPhone, DevConf,
  33.   TAPIAddress, TAPILines, TAPIDevices, TAPIServices, TAPISystem, Menus,
  34.   StdCtrls, ComCtrls, Dialogs, TAPIErr, TAPILineConfigDlg;
  35. type
  36.   TForm1 = class(TForm)
  37.     GroupBox1: TGroupBox;
  38.     Memo1: TMemo;
  39.     MainMenu1: TMainMenu;
  40.     Datei1: TMenuItem;
  41.     Beenden1: TMenuItem;
  42.     N1: TMenuItem;
  43.     Look: TMenuItem;
  44.     DialNumber: TMenuItem;
  45.     ReInit: TMenuItem;
  46.     Neu1: TMenuItem;
  47.     KeypadGroupBox: TGroupBox;
  48.     Button1: TButton;
  49.     Button2: TButton;
  50.     Button3: TButton;
  51.     Button4: TButton;
  52.     Button5: TButton;
  53.     Button6: TButton;
  54.     Button7: TButton;
  55.     Button8: TButton;
  56.     Button9: TButton;
  57.     Button10: TButton;
  58.     Button11: TButton;
  59.     Button12: TButton;
  60.     DialButton: TButton;
  61.     Label1: TLabel;
  62.     TAPILineService1: TTAPILineService;
  63.     TAPIPhoneService1: TTAPIPhoneService;
  64.     TAPILineDevice1: TTAPILineDevice;
  65.     TAPIPhoneDevice1: TTAPIPhoneDevice;
  66.     TAPILine1: TTAPILine;
  67.     TAPIAddress1: TTAPIAddress;
  68.     OutboundCall: TTAPICall;
  69.     InboundCall: TTAPICall;
  70.     StatusBar1: TStatusBar;
  71.     TAPILineDeviceConfig1: TTAPILineDeviceConfig;
  72.     ClearButton: TButton;
  73.     TAPIPhone1: TTAPIPhone;
  74.     ComboBox1: TComboBox;
  75.     ComboBox2: TComboBox;
  76.     InboundDigits: TTAPIDigits;
  77.     OutboundDigits: TTAPIDigits;
  78.     HoldButton: TButton;
  79.     HandSetVolumeBar: TProgressBar;
  80.     HandSetGainBar: TProgressBar;
  81.     HandSetGainUpDown: TUpDown;
  82.     XPManifest1: TXPManifest;
  83.     HeadSetGainBar: TProgressBar;
  84.     HeadSetVolumeBar: TProgressBar;
  85.     HeadSetVolUpDown: TUpDown;
  86.     HeadSetGainUpDown: TUpDown;
  87.     SpeakerGainBar: TProgressBar;
  88.     SpeakerVolumeBar: TProgressBar;
  89.     SpeakerGainUpDown: TUpDown;
  90.     SpeakerVolUpDown: TUpDown;
  91.     HandSetVolUpDown: TUpDown;
  92.     TAPICallList1: TTAPICallList;
  93.     SpkCheckBox: TCheckBox;
  94.     CallParams1: TCallParams;
  95.     Edit1: TEdit;
  96.     Label2: TLabel;
  97.     CallInfoBox: TGroupBox;
  98.     Label4: TLabel;
  99.     Label5: TLabel;
  100.     Label3: TLabel;
  101.     Label6: TLabel;
  102.     Label7: TLabel;
  103.     Label8: TLabel;
  104.     Label9: TLabel;
  105.     HdsCheckBox: TCheckBox;
  106.     TAPILineConfigDlg1: TTAPILineConfigDlg;
  107.     procedure Beenden1Click(Sender: TObject);
  108.     procedure FormCreate(Sender: TObject);
  109.     procedure FormDestroy(Sender: TObject);
  110.     procedure TAPILine1AfterOpen(Sender: TObject);
  111.     procedure ClearButtonClick(Sender: TObject);
  112.     procedure DialButtonClick(Sender: TObject);
  113.     procedure KeypadClick(Sender: TObject);
  114.     procedure TAPILine1BeforeOpen(Sender: TObject);
  115.     procedure TAPIPhone1Reply(Sender: TObject; AsyncFunc: TAsyncFunc;
  116.       Error: Cardinal);
  117.     procedure TAPIPhone1StateDisplay(Sender: TObject);
  118.     procedure InboundCallStateDisconnected(Sender: TObject;
  119.       DisconnectedMode: TLineDisconnectMode; Rights: TLineCallPrivilege);
  120.     procedure OutboundCallStateDisconnected(Sender: TObject;
  121.       DisconnectedMode: TLineDisconnectMode; Rights: TLineCallPrivilege);
  122.     procedure ComboBox1Change(Sender: TObject);
  123.     procedure OutboundCallStateConnected(Sender: TObject;
  124.       ConnectedMode: TLineConnectedModes; Rights: TLineCallPrivilege);
  125.     procedure InboundCallStateOnHold(Sender: TObject;
  126.       Rights: TLineCallPrivilege);
  127.     procedure InboundCallStateOffering(Sender: TObject;
  128.       OfferingMode: TLineOfferingModes; Rights: TLineCallPrivilege);
  129.     procedure InboundCallStateIdle(Sender: TObject;
  130.       Rights: TLineCallPrivilege);
  131.     procedure HoldButtonClick(Sender: TObject);
  132.     procedure InboundCallStateConnected(Sender: TObject;
  133.       ConnectedMode: TLineConnectedModes; Rights: TLineCallPrivilege);
  134.     procedure OutboundCallStateProceeding(Sender: TObject;
  135.       Rights: TLineCallPrivilege);
  136.     procedure OutboundCallStateIdle(Sender: TObject;
  137.       Rights: TLineCallPrivilege);
  138.     procedure TAPIPhone1StateHandSetGain(Sender: TObject);
  139.     procedure HandSetGainUpDownChangingEx(Sender: TObject;
  140.       var AllowChange: Boolean; NewValue: Smallint;
  141.       Direction: TUpDownDirection);
  142.     procedure TAPIPhone1StateHandSetVolume(Sender: TObject);
  143.     procedure VolUpDownChangingEx(Sender: TObject;
  144.       var AllowChange: Boolean; NewValue: Smallint;
  145.       Direction: TUpDownDirection);
  146.     procedure TAPIPhone1StateHeadSetGain(Sender: TObject);
  147.     procedure TAPIPhone1StateSpeakerGain(Sender: TObject);
  148.     procedure TAPIPhone1StateSpeakerVolume(Sender: TObject);
  149.     procedure SpeakerVolUpDownChangingEx(Sender: TObject;
  150.       var AllowChange: Boolean; NewValue: Smallint;
  151.       Direction: TUpDownDirection);
  152.     procedure SpeakerGainUpDownChangingEx(Sender: TObject;
  153.       var AllowChange: Boolean; NewValue: Smallint;
  154.       Direction: TUpDownDirection);
  155.     procedure HeadSetVolUpDownChangingEx(Sender: TObject;
  156.       var AllowChange: Boolean; NewValue: Smallint;
  157.       Direction: TUpDownDirection);
  158.     procedure HeadSetGainUpDownChangingEx(Sender: TObject;
  159.       var AllowChange: Boolean; NewValue: Smallint;
  160.       Direction: TUpDownDirection);
  161.     procedure TAPIPhone1StateHeadSetVolume(Sender: TObject);
  162.     procedure TAPILineDevice1StateClose(Sender: TObject);
  163.     procedure OutboundCallStateDialing(Sender: TObject;
  164.       Rights: TLineCallPrivilege);
  165.     procedure OutboundCallStateRingBack(Sender: TObject;
  166.       Rights: TLineCallPrivilege);
  167.     procedure OutboundCallStateDialTone(Sender: TObject;
  168.       DialTonMode: TLineDialToneMode; Rights: TLineCallPrivilege);
  169.     procedure InboundCallStateAccepted(Sender: TObject;
  170.       Rights: TLineCallPrivilege);
  171.     procedure TAPILineDevice1StateRinging(Sender: TObject; RingModeIndex,
  172.       RingCounter: Cardinal);
  173.     procedure TAPIAddress1AppNewCall(Sender: TObject; Call: TTAPICall;
  174.       AddressID: Cardinal; Privilege: TLineCallPrivilege);
  175.     procedure OutboundCallStateBusy(Sender: TObject;
  176.       BusyMode: TLineBusyMode; Rights: TLineCallPrivilege);
  177.     procedure SpkCheckBoxClick(Sender: TObject);
  178.     procedure TAPILineDevice1StateNumCalls(Sender: TObject);
  179.     procedure ReInitClick(Sender: TObject);
  180.     procedure TAPILine1Reply(Sender: TObject; AsyncFunc: TAsyncFunc;
  181.       Error: Cardinal);
  182.     procedure OutboundCallReply(Sender: TObject; AsyncFunc: TAsyncFunc;
  183.       Error: Cardinal);
  184.     procedure DialNumberClick(Sender: TObject);
  185.     procedure OutboundCallStateUnknown(Sender: TObject;
  186.       Rights: TLineCallPrivilege);
  187.     procedure ComboBox2Change(Sender: TObject);
  188.     procedure TAPIPhone1AfterOpen(Sender: TObject);
  189.     procedure TAPIPhone1BeforeOpen(Sender: TObject);
  190.     procedure LookClick(Sender: TObject);
  191.     procedure OutboundCallInfoDisplay(Sender: TObject);
  192.     procedure OutboundCallInfoOrigin(Sender: TObject);
  193.     procedure OutboundCallInfoCallerId(Sender: TObject);
  194.     procedure OutboundCallInfoCalledId(Sender: TObject);
  195.     procedure InboundCallInfoCalledId(Sender: TObject);
  196.     procedure InboundCallInfoCallerId(Sender: TObject);
  197.     procedure InboundCallInfoDisplay(Sender: TObject);
  198.     procedure InboundCallInfoOrigin(Sender: TObject);
  199.     procedure TAPILineService1LineCreate(Sender: TObject;
  200.       NewDeviceID: Cardinal);
  201.     procedure TAPIPhoneService1PhoneCreate(Sender: TObject;
  202.       NewDeviceID: Cardinal);
  203.     procedure TAPIPhoneService1PhoneRemove(Sender: TObject;
  204.       DeviceID: Cardinal);
  205.     procedure TAPILineService1LineRemove(Sender: TObject;
  206.       DeviceID: Cardinal);
  207.     procedure HdsCheckBoxClick(Sender: TObject);
  208.     procedure Neu1Click(Sender: TObject);
  209.   private
  210.     { Private-Deklarationen }
  211.     FHandsetStatus: Boolean;
  212.     FSpeakerStatus: Boolean;
  213.     FHeadSetStatus: Boolean;
  214.     FLinePriority: Boolean;
  215.     LinesFromPhone: Array[0..3]of DWord; 
  216.     function GetPhoneSupport: Boolean;
  217.     function GetCanDial: Boolean;
  218.     function GetHandset: Boolean;
  219.     function RealPos(Value:Smallint):DWord;
  220.     function VirtPos(Value:Integer):Smallint;
  221.     procedure DisplaySpeakerVol(UpdateUpDown: Boolean = False);
  222.     procedure DisplaySpeakerGain(UpdateUpDown: Boolean = False);
  223.     procedure DisplayHandSetVol(UpdateUpDown: Boolean = False);
  224.     procedure DisplayHandSetGain(UpdateUpDown: Boolean = False);
  225.     procedure DisplayHeadSetVol(UpdateUpDown: Boolean = False);
  226.     procedure DisplayHeadSetGain(UpdateUpDown: Boolean = False);
  227.     procedure SetHandSet(const Value: Boolean);
  228.     function GetCallExist(const Index: Integer): Boolean;
  229.     function GetSpeaker: Boolean;
  230.     procedure SetSpeaker(const Value: Boolean);
  231.     procedure Disconnect;
  232.     function GetLineSupport: Boolean;
  233.     procedure UpdateCallerInfo;
  234.     function GetHeadSet: Boolean;
  235.     procedure SetHeadSet(const Value: Boolean);
  236.   public
  237.     { Public-Deklarationen }
  238.     property PhoneSupport: Boolean read GetPhoneSupport;
  239.     property LineSupport: Boolean read GetLineSupport;
  240.     property CanDial: Boolean read GetCanDial;
  241.     property Handset: Boolean read GetHandset write SetHandSet;
  242.     property Speaker: Boolean read GetSpeaker write SetSpeaker;
  243.     property Headset: Boolean read GetHeadSet write SetHeadSet;
  244.     property InboundCallExist: Boolean index 1 read GetCallExist;
  245.     property OutboundCallExist:Boolean index 2 read GetCallExist;
  246.   end;
  247. var
  248.   Form1: TForm1;
  249. implementation
  250. uses linedlg;
  251. {$R *.dfm}
  252. procedure TForm1.Beenden1Click(Sender: TObject);
  253. begin
  254.   Close;
  255. end;
  256. procedure TForm1.FormCreate(Sender: TObject);
  257. var TempLineDevice: TTAPILineDevice;
  258.     TempPhoneDevice: TTAPIPhoneDevice;
  259.     i: Integer;
  260.     LastDev:Integer;
  261. begin
  262.   UpdateCallerInfo;
  263.   if TAPILineService1.Version < 3.8 then Close;
  264.   HandSetGainBar.Max:=$FFFF;
  265.   HandSetVolumeBar.Max:=$FFFF;
  266.   HeadSetGainBar.Max:=$FFFF;
  267.   HeadSetVolumeBar.Max:=$FFFF;
  268.   SpeakerGainBar.Max:=$FFFF;
  269.   SpeakerVolumeBar.Max:=$FFFF;
  270.   Label1.Caption:='';
  271.   LastDev:=0;
  272.   Memo1.Lines.Add('System - Check');
  273.   TAPILineService1.Active:=True;
  274.   TempLineDevice:=TTAPILineDevice.Create(self);
  275.   TempLineDevice.Service:=TAPILineService1;
  276.   ComboBox1.Clear;
  277.   for i:=0 to TAPILineService1.NumDevice -1 do
  278.   begin
  279.     TempLineDevice.ID:=i;
  280.     if mmInteractiveVoice in TempLineDevice.Caps.MediaModes then
  281.       LastDev:=i;
  282.     ComboBox1.Items.Add(TempLineDevice.Caps.Name);
  283.   end;
  284.   TAPILineDevice1.ID:=LastDev;
  285.   TempLineDevice.Free;
  286.   TAPIPhoneService1.Active:=True;
  287.   ComboBox2.Clear;
  288.   ComboBox2.Items.Add('Phone Support disabled');
  289.   TempPhoneDevice:=TTAPIPhoneDevice.Create(self);
  290.   try
  291.     try
  292.       TempPhoneDevice.Service:=TAPIPhoneService1;
  293.       for i:=0 to TAPIPhoneService1.NumDevice -1 do
  294.       begin
  295.         TempPhoneDevice.ID:=i;
  296.         ComboBox2.Items.Add(TempPhoneDevice.Caps.Name);
  297.       end;
  298.     except
  299.       // Not Phone Devices avalible !!
  300.     end
  301.   finally
  302.     TempPhoneDevice.Free;
  303.   end;
  304.   ComboBox2.ItemIndex:=0;
  305.   
  306.   TAPILine1.Active:=True;
  307. end;
  308. function TForm1.GetPhoneSupport: Boolean;
  309. var i: Integer;
  310. begin
  311.   Result:=False;
  312.   if TAPIPhoneService1.Active then
  313.   begin
  314.     if (TAPIPhoneService1.NumDevice > 0) then
  315.     begin
  316.       for i:=0 to 3 do
  317.       begin
  318.         If TAPILineDevice1.ID = LinesFromPhone[i] then
  319.         begin
  320.           FLinePriority:=False;
  321.           Result:=True;
  322.           break;
  323.         end;  
  324.       end;
  325.     end;
  326.   end;
  327. end;
  328. function TForm1.GetLineSupport: Boolean;
  329. begin
  330.   Result:=False;
  331.   if TAPILineService1.Active then
  332.   begin
  333.     if TAPILineService1.NumDevice > 0 then
  334.     begin
  335.       if LinesFromPhone[0]<> DWORD(-1) then
  336.       begin
  337.         FLinePriority:=False;
  338.         Result:=True;
  339.       end;
  340.     end;
  341.   end;
  342. end;   
  343. procedure TForm1.FormDestroy(Sender: TObject);
  344. begin
  345.   PlaySound(nil,hInstance,SND_PURGE);
  346.   TAPIPhoneService1.Active:=False;
  347.   TAPILineService1.Active:=False;
  348. end;
  349. procedure TForm1.TAPILine1AfterOpen(Sender: TObject);
  350. var i: Integer;
  351.     aTerm: TTermCapsItem;
  352. begin
  353.   if TAPILine1.Status.NumActiveCalls <> 0 then
  354.   begin
  355.     TAPICallList1.UpdateList;
  356.   end;
  357.   if TAPILine1.Active then Memo1.Lines.Add('Lines - Check: OK');
  358.    StatusBar1.SimpleText:=TAPILineDevice1.Caps.Name;
  359.   if PhoneSupport then
  360.   begin
  361.     //TAPIPhone1.Device.ID:=TAPILine1.PhoneID;
  362.     ComboBox2.ItemIndex:=TAPIPhone1.Device.ID+1;
  363.     TAPIPhone1.Active:=True;
  364.     //for i:=0 to 3 do LinesFromPhone[i]:=DWord(-1);
  365.     //TAPIPhone1.GetLineIDs(LinesFromPhone);
  366.     Memo1.Lines.Add(TAPIPhone1.Device.Caps.Name);
  367.     Memo1.Lines.Add('Phone - Check: OK');
  368.   end
  369.   else
  370.     Memo1.Lines.Add('Phone - Check: ERROR');
  371.   for i:=0 to TAPILine1.Device.Caps.TerminalCaps.Count-1 do
  372.   begin
  373.     aTerm:=TAPILine1.Device.Caps.TerminalCaps.Items[i];
  374.     if aTerm.TermDev = ltdPhone then
  375.     begin
  376.     end
  377.   end;
  378.   DialButton.Enabled:=CanDial;
  379.   TAPIPhone1StateDisplay(self);
  380.   DisplayHandSetGain(True);
  381.   DisplayHandSetVol(True);
  382.   DisplayHeadSetGain(True);
  383.   DisplayHeadSetVol(True);
  384.   DisplaySpeakerGain(True);
  385.   DisplaySpeakerVol(True);
  386. end;
  387. procedure TForm1.TAPIPhone1AfterOpen(Sender: TObject);
  388. var i: Integer;
  389. begin
  390.   for i:=0 to 3 do LinesFromPhone[i]:=DWord(-1);
  391.   TAPIPhone1.GetLineIDs(LinesFromPhone);
  392.   if TAPIPhone1.Active then Memo1.Lines.Add('Phone - Check: OK');
  393.    StatusBar1.SimpleText:=TAPIPhoneDevice1.Caps.Name;
  394.   if LineSupport then
  395.   begin
  396.     if LinesFromPhone[1] = DWORD(-1) then
  397.       TAPILine1.Device.ID:=LinesFromPhone[0]
  398.     else
  399.     begin
  400.       SelLineDlg:=TSelLineDlg.Create(self);
  401.       SelLineDlg.ComboBox1.Clear;
  402.       SelLineDlg.ComboBox1.ItemIndex:=-1;
  403.       for i:=0 to 3 do
  404.       begin
  405.         if LinesFromPhone[i] <> DWord(-1) then
  406.         begin
  407.           TAPILine1.Device.ID:=LinesFromPhone[i];
  408.           SelLineDlg.ComboBox1.Items.Add(TAPILine1.Device.Caps.Name);
  409.           SelLineDlg.ComboBox1.ItemIndex:=0;
  410.         end;
  411.       end;
  412.       SelLineDlg.ShowModal;
  413.       TAPILine1.Device.ID:=LinesFromPhone[SelLineDlg.ComboBox1.ItemIndex];
  414.       SelLineDlg.Free;
  415.     end;
  416.     ComboBox1.ItemIndex:=TAPILine1.Device.ID;
  417.     TAPILine1.Active:=True;
  418.     Memo1.Lines.Add(TAPILine1.Device.Caps.Name);
  419.     Memo1.Lines.Add('Line - Check: OK');
  420.   end;
  421.   DialButton.Enabled:=CanDial;
  422.   TAPIPhone1StateDisplay(self);
  423.   DisplayHandSetGain(True);
  424.   DisplayHandSetVol(True);
  425.   DisplayHeadSetGain(True);
  426.   DisplayHeadSetVol(True);
  427.   DisplaySpeakerGain(True);
  428.   DisplaySpeakerVol(True);
  429. end;
  430. procedure TForm1.ClearButtonClick(Sender: TObject);
  431. begin
  432.   Memo1.Lines.Clear;
  433.   if PhoneSupport then
  434.     TAPIPhone1StateDisplay(self);
  435.   TAPIAddress1.Address:='';
  436.   DialButton.Enabled:=CanDial;
  437. end;
  438. function TForm1.GetCanDial: Boolean;
  439. begin
  440.   Result:=False;
  441.   with TAPIAddress1 do
  442.   begin
  443.     if Line.Active and (Address <> '') and
  444.       (lfMakeCall in Line.Device.Caps.LineFeatures) then Result:=True;
  445.   end;
  446. end;
  447. procedure TForm1.DialButtonClick(Sender: TObject);
  448. //var Addr: PChar;
  449. begin
  450.   Handset:=Not(Handset);
  451.   if DialButton.Caption='Dial' then
  452.   begin
  453.     ClearButton.Enabled:=False;
  454.     //
  455.     //Addr:=PChar(Edit1.Text);
  456.     {if Not (amAddressID in TAPIAddress1.Line.Device.Caps.AddressModes ) or DialNumber.Checked then
  457.     begin
  458.       try
  459.         TAPIAddress1.GetAddressID(Addr);
  460.       except
  461.       end;
  462.       CallParams1.AddressMode:=amDialableAddr;
  463.       CallParams1.AddressID:=TAPIAddress1.ID;
  464.       CallParams1.OrigAddress:=Addr;
  465.     end
  466.     else
  467.       CallParams1.AddressMode:=amAddressID; }
  468.     TAPIAddress1.MakeCall;
  469.   end;
  470.   if DialButton.Caption='Answer'then
  471.     if InboundCallExist then InBoundCall.Answer;
  472.   if DialButton.Caption='Drop' then
  473.   begin
  474.     if InboundCallExist then InboundCall.Drop;
  475.     if OutboundCallExist then OutBoundCall.Drop;
  476.     ClearButton.Enabled:=True;
  477.     SpkCheckBox.Checked:=False;
  478.     HdsCheckBox.Checked:=False;
  479.   end;
  480. end;
  481. procedure TForm1.KeypadClick(Sender: TObject);
  482. var Key: Integer;
  483. begin
  484.   Key:=-1;
  485.   if Sender = Button1 then Key:=Button1.Tag;
  486.   if Sender = Button2 then Key:=Button2.Tag;
  487.   if Sender = Button3 then Key:=Button3.Tag;
  488.   if Sender = Button4 then Key:=Button4.Tag;
  489.   if Sender = Button5 then Key:=Button5.Tag;
  490.   if Sender = Button6 then Key:=Button6.Tag;
  491.   if Sender = Button7 then Key:=Button7.Tag;
  492.   if Sender = Button8 then Key:=Button8.Tag;
  493.   if Sender = Button9 then Key:=Button9.Tag;
  494.   if Sender = Button10 then Key:=Button10.Tag;
  495.   if Sender = Button11 then Key:=Button11.Tag;
  496.   if Sender = Button12 then Key:=Button12.Tag;
  497.   if (TAPILine1.Status.NumActiveCalls <> DWord(-1)) then
  498.   begin
  499.     if Key < 10 then
  500.       TAPIAddress1.Address:=TAPIAddress1.Address+IntToStr(Key)
  501.     else
  502.     begin
  503.       if Key=10 then TAPIAddress1.Address:=TAPIAddress1.Address+'*';
  504.       if Key=11 then TAPIAddress1.Address:=TAPIAddress1.Address+'#';
  505.     end;
  506.   end
  507.   else
  508.   begin
  509.     InBoundDigits.GenerateDigits:=IntToStr(Key);
  510.     InBoundDigits.GenerateDigit;
  511.     OutBoundDigits.GenerateDigits:=IntToStr(Key);
  512.     OutBoundDigits.GenerateDigit;
  513.   end;
  514.   DialButton.Enabled:=CanDial;
  515.   TAPIPhone1StateDisplay(self);
  516. end;
  517. function TForm1.GetHeadSet: Boolean;
  518. begin
  519.   Result:=FHeadSetStatus;
  520.   if PhoneSupport then
  521.     Result:=Result and not(phsmOnHook = TAPIPhone1.Status.HeadSetHookSwitchMode);
  522. end;
  523. procedure TForm1.SetHeadSet(const Value: Boolean);
  524. begin
  525.   if FHeadSetStatus <> Value then
  526.   begin
  527.     if PhoneSupport then
  528.     begin
  529.       if pfSetHookSwitchHeadSet in TAPIPhone1.Device.Caps.PhoneFeatures then
  530.         if Value then
  531.           TAPIPhone1.HeadSetHookSwitchMode:=phsmMicSpeaker
  532.         else
  533.           TAPIPhone1.HeadSetHookSwitchMode:=phsmOnHook;
  534.     end;
  535.     FHeadSetStatus:=Value;
  536.   end;
  537. end;
  538. function TForm1.GetHandset: Boolean;
  539. begin
  540.   Result:=FHandsetStatus;
  541.   if PhoneSupport then
  542.     Result:=Result and not(phsmOnHook = TAPIPhone1.Status.HandSetHookSwitchMode);
  543.     //.HandSetHookSwitchOffHook;
  544. end;
  545. procedure TForm1.SetHandSet(const Value: Boolean);
  546. begin
  547.   if FHandsetStatus <> Value then
  548.   begin
  549.     if PhoneSupport then
  550.     begin
  551.       if pfSetHookSwitchHandset in TAPIPhone1.Device.Caps.PhoneFeatures then
  552.         if Value then
  553.           TAPIPhone1.HandSetHookSwitchMode:=phsmMicSpeaker
  554.         else
  555.           TAPIPhone1.HandSetHookSwitchMode:=phsmOnHook;
  556.     end;
  557.     FHandsetStatus:=Value;
  558.   end;
  559. end;
  560. function TForm1.GetSpeaker: Boolean;
  561. begin
  562.   Result:=FSpeakerStatus;
  563.   if PhoneSupport then
  564.     Result:=Result and not(phsmOnHook = TAPIPhone1.Status.SpeakerHookSwitchMode);
  565. end;
  566. procedure TForm1.SetSpeaker(const Value: Boolean);
  567. begin
  568.   if FSpeakerStatus <> Value then
  569.   begin
  570.     if PhoneSupport then
  571.     begin
  572.       if pfSetHookSwitchSpeaker in TAPIPhone1.Device.Caps.PhoneFeatures then
  573.         if Value then
  574.           TAPIPhone1.SpeakerHookSwitchMode:=phsmMicSpeaker
  575.         else
  576.           TAPIPhone1.SpeakerHookSwitchMode:=phsmOnHook;
  577.     end;
  578.     FSpeakerStatus:=Value;
  579.   end;
  580. end;
  581. procedure TForm1.TAPILine1BeforeOpen(Sender: TObject);
  582. begin
  583.   ComboBox1.ItemIndex:=TAPILine1.Device.ID;
  584. end;
  585. procedure TForm1.TAPIPhone1Reply(Sender: TObject; AsyncFunc: TAsyncFunc;
  586.   Error: Cardinal);
  587. begin
  588.   if Error <> 0 then Memo1.Lines.Add('Error');
  589. end;
  590. procedure TForm1.TAPIPhone1StateDisplay(Sender: TObject);
  591. var i: Integer;
  592.     s: String;
  593. begin
  594.   Memo1.Lines.Clear;
  595.   if PhoneSupport and (TAPIPhone1.Display.NumRows >=1) then
  596.   begin
  597.     s:= TAPIPhone1.Display.GetDisplay;
  598.     for i:=0 to TAPIPhone1.Display.NumRows do
  599.       Memo1.Lines.Add(copy(s,i*(TAPIPhone1.Display.NumColumn+1),TAPIPhone1.Display.NumColumn));
  600.   end
  601.   else
  602.   begin
  603.     Memo1.Lines.Add(TAPIAddress1.Address);
  604.   end;
  605. end;
  606. procedure TForm1.Disconnect;
  607. begin
  608.   Label1.Caption:='';
  609.   HoldButton.Enabled:=False;
  610.   ClearButton.Enabled:=True;
  611.   DialButton.Caption:='Dial';
  612.   SpkCheckBox.Enabled:=False;
  613.   SpkCheckBox.Checked:=False;
  614.   HdsCheckBox.Enabled:=False;
  615.   HdsCheckBox.Checked:=False;
  616. end;
  617. procedure TForm1.InboundCallStateDisconnected(Sender: TObject;
  618.   DisconnectedMode: TLineDisconnectMode; Rights: TLineCallPrivilege);
  619. begin
  620.   Disconnect;
  621.   InboundCall.DeallocateCall;
  622. end;
  623. procedure TForm1.OutboundCallStateDisconnected(Sender: TObject;
  624.   DisconnectedMode: TLineDisconnectMode; Rights: TLineCallPrivilege);
  625. begin
  626.   PlaySound(nil,0,SND_ALIAS or SND_ASYNC or SND_LOOP);
  627.   Disconnect;
  628.   PlaySound(nil,hInstance,SND_PURGE);
  629.   OutBoundCall.DeallocateCall;
  630. end;
  631. procedure TForm1.ComboBox1Change(Sender: TObject);
  632. begin
  633.   ClearButton.Enabled:=True;
  634.   Combobox2.ItemIndex:=0;
  635.   TAPILine1.Active:=False;
  636.   TAPIPhone1.Active:=False;
  637.   TAPILine1.Device.ID:=ComboBox1.ItemIndex;
  638.   try
  639.     TAPILine1.Active:=True;
  640.   except
  641.     on ELineError do MessageDlg('Line not active! ',mtError,[mbOK],0);
  642.   end
  643. end;
  644. procedure TForm1.ComboBox2Change(Sender: TObject);
  645. var i: Integer;
  646. begin
  647.   ClearButton.Enabled:=True;
  648.   //Combobox1.ItemIndex:=0;
  649.   TAPILine1.Active:=False;
  650.   TAPIPhone1.Active:=False;
  651.   if ComboBox2.ItemIndex > 0 then
  652.   begin
  653.     TAPIPhoneDevice1.ID:=ComboBox2.ItemIndex -1;
  654.     try
  655.       TAPIPhone1.Active:=True;
  656.     except
  657.       on ELineError do MessageDlg('Phone not active! ',mtError,[mbOK],0);
  658.     end
  659.   end
  660.   else
  661.   begin
  662.     for i:=0 to 3 do LinesFromPhone[i]:=DWord(-1);
  663.     TAPILine1.Active:=True;
  664.   end;
  665. end;
  666. procedure TForm1.OutboundCallStateConnected(Sender: TObject;
  667.   ConnectedMode: TLineConnectedModes; Rights: TLineCallPrivilege);
  668. begin
  669.   Label1.Caption:='Please speak now';
  670.   SpkCheckBox.Enabled:=True;
  671.   HdsCheckBox.Enabled:=True;
  672.   HoldButton.Enabled:=lcfHold in TAPIAddress1.Caps.CallFeatures;
  673.   DialButton.Caption:='Drop';
  674. end;
  675. procedure TForm1.InboundCallStateConnected(Sender: TObject;
  676.   ConnectedMode: TLineConnectedModes; Rights: TLineCallPrivilege);
  677. begin
  678.   Label1.Caption:='Please speak now';
  679.   SpkCheckBox.Enabled:=True;
  680.   HoldButton.Enabled:=lcfHold in TAPIAddress1.Caps.CallFeatures;
  681.   DialButton.Caption:='Drop';
  682. end;
  683. procedure TForm1.InboundCallStateOnHold(Sender: TObject;
  684.   Rights: TLineCallPrivilege);
  685. begin
  686.   Label1.Caption:='Call is hold now';
  687. end;
  688. procedure TForm1.InboundCallStateOffering(Sender: TObject;
  689.   OfferingMode: TLineOfferingModes; Rights: TLineCallPrivilege);
  690. begin
  691.   if Rights=[] then Rights:=TAPIAddress1.InBoundCall.Status.CallPrivilege;
  692.   if (cpOwner in Rights) then
  693.   begin
  694.     if (lomActive in OfferingMode) or (OfferingMode=[])then
  695.       if lacfAcceptToAlert in TAPIAddress1.Caps.AddrCapFlags then
  696.         TAPIAddress1.InBoundCall.Accept;
  697.       if lafPickup in TAPIAddress1.Status.AddressFeatures then
  698.       begin
  699.         //  TAPIAddress1.Pickup;
  700.       end;
  701.     //DialButton.Caption:='Answer';
  702.     //DialButton.Enabled:=True;
  703.     //Label1.Caption:='Press Answer to speak';
  704.   end;
  705. end;
  706. procedure TForm1.InboundCallStateIdle(Sender: TObject;
  707.   Rights: TLineCallPrivilege);
  708. begin
  709.   Label1.Caption:='';
  710.   InboundCall.DeallocateCall;
  711.   DialButton.Caption:='Dial';
  712. end;
  713. procedure TForm1.HoldButtonClick(Sender: TObject);
  714. begin
  715.   if InboundCallExist then
  716.   begin
  717.     if csOnHold in InboundCall.Status.State  then
  718.       InboundCall.UnHold
  719.     else
  720.       InboundCall.Hold;
  721.   end;
  722.   if OutboundCallExist then
  723.   begin
  724.     if csOnHold in OutboundCall.Status.State then
  725.       OutboundCall.UnHold
  726.     else
  727.       OutboundCall.Hold;
  728.   end;
  729. end;
  730. function TForm1.GetCallExist(const Index: Integer): Boolean;
  731. begin
  732.   case Index of
  733.     1: if (InboundCall.Handle <> DWORD(-1)) then Result:=True else Result:=False;
  734.     2: if (OutboundCall.Handle <> DWORD(-1))then Result:=True else Result:=False;
  735.   else
  736.     Result:=False;
  737.   end;
  738. end;
  739. procedure TForm1.OutboundCallStateProceeding(Sender: TObject;
  740.   Rights: TLineCallPrivilege);
  741. begin
  742.   Label1.Caption:='Proceeding ...';
  743.   DialButton.Caption:='Drop';
  744. end;
  745. procedure TForm1.OutboundCallStateIdle(Sender: TObject;
  746.   Rights: TLineCallPrivilege);
  747. begin
  748.   Disconnect;
  749.   Label1.Caption:='';
  750.   OutboundCall.DeallocateCall;
  751.   DialButton.Caption:='Dial';
  752. end;
  753. procedure TForm1.TAPIPhone1StateHandSetGain(Sender: TObject);
  754. begin
  755.   DisplayHandSetGain;
  756. end;
  757. procedure TForm1.TAPIPhone1StateHandSetVolume(Sender: TObject);
  758. begin
  759.   DisplayHandSetVol;
  760. end;
  761. procedure TForm1.TAPIPhone1StateHeadSetGain(Sender: TObject);
  762. begin
  763.   DisplayHeadSetGain;
  764. end;
  765. procedure TForm1.TAPIPhone1StateHeadSetVolume(Sender: TObject);
  766. begin
  767.   DisplayHeadSetVol;
  768. end;
  769. procedure TForm1.TAPIPhone1StateSpeakerGain(Sender: TObject);
  770. begin
  771.   DisplaySpeakerGain;
  772. end;
  773. procedure TForm1.TAPIPhone1StateSpeakerVolume(Sender: TObject);
  774. begin
  775.   DisplaySpeakerVol;
  776. end;
  777. procedure TForm1.HandSetGainUpDownChangingEx(Sender: TObject;
  778.   var AllowChange: Boolean; NewValue: Smallint;
  779.   Direction: TUpDownDirection);
  780. begin
  781.   TAPIPhone1.HandSetGain:=RealPos(NewValue);
  782. end;
  783. procedure TForm1.VolUpDownChangingEx(Sender: TObject;
  784.   var AllowChange: Boolean; NewValue: Smallint;
  785.   Direction: TUpDownDirection);
  786. begin
  787.   TAPIPhone1.HandSetVolume:=RealPos(NewValue);
  788. end;
  789. procedure TForm1.SpeakerVolUpDownChangingEx(Sender: TObject;
  790.   var AllowChange: Boolean; NewValue: Smallint;
  791.   Direction: TUpDownDirection);
  792. begin
  793.   TAPIPhone1.SpeakerVolume:=RealPos(NewValue);
  794. end;
  795. procedure TForm1.SpeakerGainUpDownChangingEx(Sender: TObject;
  796.   var AllowChange: Boolean; NewValue: Smallint;
  797.   Direction: TUpDownDirection);
  798. begin
  799.   TAPIPhone1.SpeakerGain:=RealPos(NewValue);
  800. end;
  801. procedure TForm1.HeadSetVolUpDownChangingEx(Sender: TObject;
  802.   var AllowChange: Boolean; NewValue: Smallint;
  803.   Direction: TUpDownDirection);
  804. begin
  805.   TAPIPhone1.HeadSetVolume:=RealPos(NewValue);
  806. end;
  807. procedure TForm1.HeadSetGainUpDownChangingEx(Sender: TObject;
  808.   var AllowChange: Boolean; NewValue: Smallint;
  809.   Direction: TUpDownDirection);
  810. begin
  811.   TAPIPhone1.HeadSetGain:=RealPos(NewValue);
  812. end;
  813. function TForm1.RealPos(Value: Smallint): DWord;
  814. begin
  815.   Result:=Trunc((Value / 100)*$FFFF);
  816. end;
  817. function TForm1.VirtPos(Value: Integer): Smallint;
  818. begin
  819.   Result:=Trunc((Value / $FFFF)*100);
  820. end;
  821. procedure TForm1.DisplaySpeakerVol(UpdateUpDown: Boolean = False);
  822. begin
  823.   if PhoneSupport=False then
  824.   begin
  825.     SpeakerVolUpDown.Enabled:=False;
  826.     SpeakerVolUpDown.Visible:=False;
  827.     SpeakerVolumeBar.Visible:=False;
  828.   end
  829.   else
  830.   begin
  831.     SpeakerVolUpDown.Visible:=True;
  832.     SpeakerVolumeBar.Visible:=True;
  833.     SpeakerVolUpDown.Enabled:=TAPIPhone1.Device.Caps.SpeakerHookSwitchVolumeFlag;
  834.     SpeakerVolumeBar.Position:=TAPIPhone1.SpeakerVolume;
  835.     if UpdateUpDown then
  836.       SpeakerVolUpDown.Position:=VirtPos(TAPIPhone1.SpeakerVolume);
  837.   end;
  838. end;
  839. procedure TForm1.DisplaySpeakerGain(UpdateUpDown: Boolean = False);
  840. begin
  841.   if PhoneSupport=False then
  842.   begin
  843.     SpeakerGainUpDown.Enabled:=False;
  844.     SpeakerGainUpDown.Visible:=False;
  845.     SpeakerGainBar.Visible:=False;
  846.   end
  847.   else
  848.   begin
  849.     SpeakerGainUpDown.Visible:=True;
  850.     SpeakerGainBar.Visible:=True;
  851.     SpeakerGainUpDown.Enabled:=TAPIPhone1.Device.Caps.SpeakerHookSwitchGainFlag;
  852.     SpeakerGainBar.Position:=TAPIPhone1.SpeakerGain;
  853.     if UpdateUpDown then
  854.       SpeakerGainUpDown.Position:=VirtPos(TAPIPhone1.SpeakerGain);
  855.   end;
  856. end;
  857. procedure TForm1.DisplayHandSetGain(UpdateUpDown: Boolean = False);
  858. begin
  859.   if PhoneSupport=False then
  860.   begin
  861.     HandSetGainUpDown.Enabled:=False;
  862.     HandSetGainUpDown.Visible:=False;
  863.     HandSetGainBar.Visible:=False;
  864.   end
  865.   else
  866.   begin
  867.     HandSetGainUpDown.Visible:=True;
  868.     HandSetGainBar.Visible:=True;
  869.     HandSetGainUpDown.Enabled:=TAPIPhone1.Device.Caps.HandsetHookSwitchGainFlag;
  870.     HandSetGainBar.Position:=TAPIPhone1.HandSetGain;
  871.     if UpdateUpDown then
  872.       HandSetGainUpDown.Position:=VirtPos(TAPIPhone1.HandSetGain);
  873.   end;
  874. end;
  875. procedure TForm1.DisplayHandSetVol(UpdateUpDown: Boolean = False);
  876. begin
  877.   if PhoneSupport=False then
  878.   begin
  879.     HandSetVolUpDown.Enabled:=False;
  880.     HandSetVolUpDown.Visible:=False;
  881.     HandSetVolumeBar.Visible:=False;
  882.   end
  883.   else
  884.   begin
  885.     HandSetVolUpDown.Visible:=True;
  886.     HandSetVolumeBar.Visible:=True;
  887.     HandSetVolUpDown.Enabled:=TAPIPhone1.Device.Caps.HandsetHookSwitchVolumeFlag;
  888.     HandSetVolumeBar.Position:=TAPIPhone1.HandSetVolume;
  889.     if UpdateUpDown then
  890.       HandSetVolUpDown.Position:=VirtPos(TAPIPhone1.HandSetVolume);
  891.   end;
  892. end;
  893. procedure TForm1.DisplayHeadSetGain(UpdateUpDown: Boolean = False);
  894. begin
  895.   if PhoneSupport=False then
  896.   begin
  897.     HeadSetGainUpDown.Enabled:=False;
  898.     HeadSetGainUpDown.Visible:=False;
  899.     HeadSetGainBar.Visible:=False;
  900.   end
  901.   else
  902.   begin
  903.     HeadSetGainUpDown.Visible:=True;
  904.     HeadSetGainBar.Visible:=True;
  905.     HeadSetGainUpDown.Enabled:=TAPIPhone1.Device.Caps.HeadsetHookSwitchGainFlag;
  906.     HeadSetGainBar.Position:=TAPIPhone1.HeadSetGain;
  907.     if UpdateUpDown then
  908.       HeadSetGainUpDown.Position:=VirtPos(TAPIPhone1.HeadSetGain);
  909.   end;
  910. end;
  911. procedure TForm1.DisplayHeadSetVol(UpdateUpDown: Boolean = False);
  912. begin
  913.   if PhoneSupport=False then
  914.   begin
  915.     HeadSetVolUpDown.Enabled:=False;
  916.     HeadSetVolUpDown.Visible:=False;
  917.     HeadSetVolumeBar.Visible:=False;
  918.   end  
  919.   else
  920.   begin
  921.     HeadSetVolUpDown.Visible:=True;
  922.     HeadSetVolumeBar.Visible:=True;
  923.     HeadSetVolUpDown.Enabled:=TAPIPhone1.Device.Caps.HeadsetHookSwitchVolumeFlag;
  924.     HeadSetVolumeBar.Position:=TAPIPhone1.HeadSetVolume;
  925.     if UpdateUpDown then
  926.       HeadSetVolUpDown.Position:=VirtPos(TAPIPhone1.HeadSetVolume);
  927.   end;
  928. end;
  929. procedure TForm1.TAPILineDevice1StateClose(Sender: TObject);
  930. begin
  931.   MessageDlg('Device is Closed',mtInformation,[mbOK],0);
  932. end;
  933. procedure TForm1.OutboundCallStateDialing(Sender: TObject;
  934.   Rights: TLineCallPrivilege);
  935. begin
  936.   PlaySound(nil,0,SND_ALIAS or SND_ASYNC or SND_LOOP);
  937.   PlaySound(nil,hInstance,SND_PURGE);
  938.   Label1.Caption:='Dialing ...';
  939. end;
  940. procedure TForm1.OutboundCallStateRingBack(Sender: TObject;
  941.   Rights: TLineCallPrivilege);
  942. begin
  943.   Label1.Caption:='Ring Back';
  944. end;
  945. procedure TForm1.OutboundCallStateDialTone(Sender: TObject;
  946.   DialTonMode: TLineDialToneMode; Rights: TLineCallPrivilege);
  947. var SMode: String;
  948. begin
  949.   PlaySound(nil,0,SND_ALIAS or SND_ASYNC or SND_LOOP);
  950.   PlaySound(nil,hInstance,SND_PURGE);
  951.   case DialTonMode of
  952.     dtmNormal: SMode:='normal';
  953.     dtmSpecial: SMode:='special';
  954.     dtmInternal: SMode:='internal';
  955.     dtmExternal: SMode:='external';
  956.     dtmUnknown: SMode:='unknown';
  957.     dtmUnavail: SMode:='unavail';
  958.   end;
  959.   Label1.Caption:='Dialton '+SMode;
  960. end;
  961. procedure TForm1.InboundCallStateAccepted(Sender: TObject;
  962.   Rights: TLineCallPrivilege);
  963. begin
  964.   DialButton.Caption:='Answer';
  965.   DialButton.Enabled:=True;
  966.   Label1.Caption:='Press Answer to speak';
  967. end;
  968. procedure TForm1.TAPILineDevice1StateRinging(Sender: TObject;
  969.   RingModeIndex, RingCounter: Cardinal);
  970. begin
  971.   DialButton.Caption:='Answer';
  972.   DialButton.Enabled:=True;
  973.   Label1.Caption:='Press Answer to speak ';
  974.   if RingCounter > 5 then
  975.   begin
  976.     DialButton.Enabled:=False;
  977.     InboundCall.Drop;
  978.   end;
  979. end;
  980. procedure TForm1.TAPIAddress1AppNewCall(Sender: TObject; Call: TTAPICall;
  981.   AddressID: Cardinal; Privilege: TLineCallPrivilege);
  982. begin
  983.   UpdateCallerInfo;
  984.   {if OutBoundCall.Handle = Call.Handle then
  985.     OutBoundCall.Accept; }
  986. end;
  987. procedure TForm1.OutboundCallStateBusy(Sender: TObject;
  988.   BusyMode: TLineBusyMode; Rights: TLineCallPrivilege);
  989. begin
  990.   PlaySound(nil,0,SND_ALIAS or SND_ASYNC or SND_LOOP);
  991.   PlaySound(nil,hInstance,SND_PURGE);
  992.   if lcfCompleteCall in OutBoundCall.Status.Features then
  993.   begin
  994.     OutBoundCall.CompletionMode:=lccmCampon;
  995.     OutBoundCall.CompleteCall;
  996.   end;
  997. end;
  998. procedure TForm1.SpkCheckBoxClick(Sender: TObject);
  999. begin
  1000.   Speaker:=Not(Speaker);
  1001. end;
  1002. procedure TForm1.HdsCheckBoxClick(Sender: TObject);
  1003. begin
  1004.   HeadSet:=Not(HeadSet);
  1005. end;
  1006. procedure TForm1.TAPILineDevice1StateNumCalls(Sender: TObject);
  1007. begin
  1008.  // DEBUG
  1009. end;
  1010. procedure TForm1.ReInitClick(Sender: TObject);
  1011. begin
  1012.   TAPIPhone1.Active:=False;
  1013.   TAPILine1.Active:=False;
  1014.   TAPIPhoneService1.Active:=False;
  1015.   TAPILineService1.Active:=False;
  1016.   TAPIAddress1.Address:='';
  1017.   Sleep(1000);
  1018.   TAPILineService1.Active:=True;
  1019.   TAPIPhoneService1.Active:=True;
  1020.   TAPILine1.Active:=True;
  1021. end;
  1022. procedure TForm1.TAPILine1Reply(Sender: TObject; AsyncFunc: TAsyncFunc;
  1023.   Error: Cardinal);
  1024. begin
  1025.   if Error <> 0 then Label1.Caption:='Line Error';
  1026. end;
  1027. procedure TForm1.OutboundCallReply(Sender: TObject; AsyncFunc: TAsyncFunc;
  1028.   Error: Cardinal);
  1029. begin
  1030.   if Error <> 0 then Label1.Caption:='Call Error'
  1031.   else
  1032.   if AsyncFunc =afMakeCall then
  1033.   begin
  1034.     Label1.Caption:='Please use your Handset';
  1035.     PlaySound('RingOut',0,SND_ALIAS or SND_ASYNC or SND_LOOP);
  1036.   end;  
  1037. end;
  1038. procedure TForm1.DialNumberClick(Sender: TObject);
  1039. begin
  1040.   DialNumber.Checked:=Not(DialNumber.Checked);
  1041. end;
  1042. procedure TForm1.OutboundCallStateUnknown(Sender: TObject;
  1043.   Rights: TLineCallPrivilege);
  1044. begin
  1045.   OutBoundCall.SetMediaMode([mmInteractiveVoice]);
  1046. end;
  1047. procedure TForm1.TAPIPhone1BeforeOpen(Sender: TObject);
  1048. begin
  1049.   ComboBox2.ItemIndex:=TAPIPhone1.Device.ID+1;
  1050. end;
  1051. procedure TForm1.LookClick(Sender: TObject);
  1052. begin
  1053.   Look.Checked:=Not(Look.Checked);
  1054.   KeypadGroupBox.Enabled:=Not(Look.Checked);
  1055. end;
  1056. procedure TForm1.UpdateCallerInfo;
  1057. var usedInfo: TCallInfo;
  1058. begin
  1059.   usedInfo:=nil;
  1060.   if InboundCallExist then usedInfo:=InboundCall.Info;
  1061.   if OutboundCallExist then usedInfo:=OutboundCall.Info;
  1062.   if InboundCallExist or OutboundCallExist then
  1063.   begin
  1064.     with usedInfo do
  1065.     begin
  1066.       case Origin of
  1067.         coOutBound: Label5.Caption:='OutBound';
  1068.         coInternal: Label5.Caption:='Internal';
  1069.         coExternal: Label5.Caption:='External';
  1070.         coUnknown: Label5.Caption:='Unknown';
  1071.         coUnavail: Label5.Caption:='Unavail';
  1072.         coConference: Label5.Caption:='Conference';
  1073.         coInbound: Label5.Caption:='Inbound';
  1074.       end;
  1075.       Label6.Caption:=CallerID;
  1076.       Label8.Caption:=CalledID;
  1077.       Label9.Caption:=Display;
  1078.     end;
  1079.   end
  1080.   else
  1081.   begin
  1082.     Label5.Caption:='';
  1083.     Label6.Caption:='';
  1084.     Label8.Caption:='';
  1085.     Label9.Caption:='';
  1086.   end;
  1087. end;
  1088. procedure TForm1.OutboundCallInfoDisplay(Sender: TObject);
  1089. begin
  1090.   UpdateCallerInfo;
  1091. end;
  1092. procedure TForm1.OutboundCallInfoOrigin(Sender: TObject);
  1093. begin
  1094.   UpdateCallerInfo;
  1095. end;
  1096. procedure TForm1.OutboundCallInfoCallerId(Sender: TObject);
  1097. begin
  1098.   UpdateCallerInfo;
  1099. end;
  1100. procedure TForm1.OutboundCallInfoCalledId(Sender: TObject);
  1101. begin
  1102.   UpdateCallerInfo;
  1103. end;
  1104. procedure TForm1.InboundCallInfoCalledId(Sender: TObject);
  1105. begin
  1106.   UpdateCallerInfo;
  1107. end;
  1108. procedure TForm1.InboundCallInfoCallerId(Sender: TObject);
  1109. begin
  1110.   UpdateCallerInfo;
  1111. end;
  1112. procedure TForm1.InboundCallInfoDisplay(Sender: TObject);
  1113. begin
  1114.   UpdateCallerInfo;
  1115. end;
  1116. procedure TForm1.InboundCallInfoOrigin(Sender: TObject);
  1117. begin
  1118.   UpdateCallerInfo;
  1119. end;
  1120. procedure TForm1.TAPILineService1LineCreate(Sender: TObject;
  1121.   NewDeviceID: Cardinal);
  1122. begin
  1123.   ReInitClick(Self);
  1124. end;
  1125. procedure TForm1.TAPIPhoneService1PhoneCreate(Sender: TObject;
  1126.   NewDeviceID: Cardinal);
  1127. begin
  1128.   ReInitClick(Self);
  1129. end;
  1130. procedure TForm1.TAPIPhoneService1PhoneRemove(Sender: TObject;
  1131.   DeviceID: Cardinal);
  1132. begin
  1133.   ReInitClick(Self);
  1134. end;
  1135. procedure TForm1.TAPILineService1LineRemove(Sender: TObject;
  1136.   DeviceID: Cardinal);
  1137. begin
  1138.   ReInitClick(Self);
  1139. end;
  1140. procedure TForm1.Neu1Click(Sender: TObject);
  1141. begin
  1142.   TAPILineConfigDlg1.Execute;
  1143. end;
  1144. end.