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

TAPI编程

开发平台:

C++ Builder

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