Working with Calls
 

The telephone call plays a leading role within the computer telephony. It is used to establish connections, build conferences, transfer data and so on.

The ThbTapiLine component simplifies the management of calls by giving you access to call related information and events while insulating you from the memory allocation and deallocation, call status, call creation and call destruction issues. ThbTapiLine is designed to manage multiple calls simultaneously where each call is represented by a ThbTapiCall object. The ThbTapiCall object provides you with properties and methods making the call handling very simple to use.

Many of the ThbTapiLine events have a Call parameter that indicates the call for which the event has fired. This parameter can be used directly to handle the call. Another property of ThbTapiLine that you will use when working with calls is ThbTapiLine.Calls. This property is a list of ThbTapiCall objects that holds all calls currently available on the line device.

The standard policy when working with calls is:

  Select and activate the line device.
  After activation, check the Calls property for existing calls.
  During runtime, handle the OnCallState event.
  Sometimes you need to handle the OnCallDeallocate event. It is triggered when the call has become idle and is deallocated by ThbTapiLine. After this event has fired, the call object is no longer available and all pointers to it should be cleared.

Example

interface
uses hbTapi, tapi, ...

procedure TForm1.Create(Sender: TObject);
begin
  hbTapiLine1.DeviceName := GetStoredDeviceName;
  hbTapiLine1.MediaModes := LINEMEDIAMODE_INTERACTIVEVOICE;
  hbTapiLine1.Privileges.AutoSelect := True;
  try
    hbTapiLine1.Active := True;
    for i := 0 to hbTapiLine1.Calls.Count -1 do
      DisplayCall(hbTapiLine1.Calls[i]);
  except
    on EhbTapiError do
      MessageDlg('Initialization failed!' + E.Message, mtError, [mbOk], 0);
  end;
end;

procedure TForm1.hbTapiLine1CallState(Sender: ThbTapiLine; Call: ThbTapiCall;
CallState: Cardinal);
begin
  DisplayCall(Call);
  case CallState of
    LINECALLSTATE_CONNECTED : HandleCallConnection(Call);
  end;
end;

procedure TForm1.hbTapiLine1CallDeallocate(Sender: ThbTapiLine; Call: ThbTapiCall);
begin
  HandleCallDeallocate;
end;