All available devices are listed in the DeviceList property of ThbTapiLine
resp. ThbTapiPhone. In this list, the index of a device is equal to the
deviceID. To select a device you are able to set either the DeviceID or
the DeviceName. If you set the DeviceID the DeviceName property will be
updated. If you set the DeviceName property the name must match exactly
the desired device. The DeviceID will be updated too.
procedure Form1.FormCreate(Sender: TObject);
begin
Combobox1.Items.Assign(hbTapiLine1.DeviceList);
end;
procedure Form1.Combobox1Change(Sender: TObject);
begin
hbTapiLine1.DeviceID := ComboBox1.ItemIndex;
// - or - hbTapiLine1.DeviceName := Combobox1.Text;
if hbTapiLine1.Avaialble then
begin
// open the device
end
else
begin
// display error
end;
end;
How to activate a telephony line
resp. phone device
Use the DeviceList property of ThbTapiLine resp. ThbTapiPhone to get the
installed devices. Then set the DeviceID or DeviceName property to one
of the devices.
procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBoxDevice.Items := hbTapiLine1.DeviceList; // Fill the
ComoBox with all available telephony line devices
end;
procedure TForm1.ComboBoxDeviceChange(Sender: TObject);
begin
// If hbTapiLine1 is currently open then close it
hbTapiLine1.Active := False;
// Set hbTapiLine1 to use the device selected
hbTapiLine1.DeviceID := ComboBoxDevice.ItemIndex;
// If there was a problem opening hbTapiLine1 last time then
make sure that the
// following properties are reset to their default.
hbTapiLine1.Privileges.Monitor
:= True;
hbTapiLine1.Privileges.Owner := True;
try
hbTapiLine1.Active := True;
// at this position the device is open/active
except
on E:EhbTapiError do
begin
// prove the ErrorCode
if (E.ErrorCode = LINEERR_INVALMEDIAMODE) then
begin
// this error typically occurs if
using the Unimodem-Driver
// Try it again with no privileges
hbTapiLine1.Privileges.Owner := False;
try
hbTapiLine1.Active
:= True;
except
on E:EhbTapiError
do
MessageDlg(Format('Error
opening line device: %s (ErrorCode=%d)', [E.Message, E.ErrorCode]), mtError,
[mbOk],0);
end;
end
else
MessageDlg(Format('Error opening line
device: %s (ErrorCode=%d)', [E.Message, E.ErrorCode]), mtError, [mbOk],0);
end;
end;
How to make a call
There are two different ways to make a call. The easiest is to use the
ThbTapiLine.CallParams property for call parameters. This property can be
set up at Design-Time and used as a default for all new calls.
procedure TForm1.MakeCall(PhoneNo: String);
begin
try
// See the ThbTapiLine.CallParams property for used
parameters
hbTapiLine1.MakeCall(PhoneNo);
except
// handle errors
end;
end;
or use the ThbTapiCallParams instead of ThbTapiLine.CallParams
procedure TForm1.MakeCall(PhoneNo: String);
var cp: ThbTapiCallParams;
begin
cp := ThbTapiCallParams.Create;
try
cp.AddressMode := LINEADDRESSMODE_ADDRESSID; //
Default
cp.AddressID := 0; // Default
cp.MediaMode := LINEMEDIAMODE_DATAMODEM;
// Select the media mode of the new call
cp.Flags :=
0; // No special flags, default
cp.NoAnswerTimeout := 3; // Number of seconds
till timeout
hbTapiLine1.MakeCall(PhoneNo, 0, cp.TapiData);
finally
cp.Free;
end;
end;
How to get the capabilities of a line device
Select a device by setting the DeviceID or DeviceName property. Than
use the Caps property to get the capabilities.
// uses hbTapi, Tapi;
hbTapiLine1.DeviceName := 'Standard 14400 bps Modem';
if hbTapiLine1.Avaialble then
begin
if hbTapiLine1.Caps.MediaModes
and LINEMEDIAMODE_DATAMODEM > 0 then
begin
// This device supports binary data communications
end;
end;
How to answer an incoming call
A call can usually be answered when it is offering or accepted.
Check the ThbTapiCall.State
property to become aware of the current call state. An offering call is
indicated by a ThbTapiLine.OnOffering
event. Use the ThbTapiCall.Answer
method to answer the call.
When the ThbTapiLine.OnCallerID
event fires then the ThbTapiLine.Call.CallerID properties have been updated.
The ThbTapiLine.OnCallerID event may fire more than once. In some telephonie
systems the CallerID information is available when the call begins. In
this case the ThbTapiLine.OnCallerID event may not fire. You should use
the ThbTapiLine.OnOffering
event and check the Call.CallerID.Flags
property to see if the information is available.
procedure TForm1.TapiLineCallState(Sender: ThbTapiLine;
Call: ThbTapiCall);
begin
if Call.CallerID.NameAvail then
Label1.Caption := Call.CallerID.Name;
if Call.CallerID.AddressAvail then
Label2.Caption := Call.CallerID.Address;
end;
// The OnCallerID events is fired when the CallerID has changed
procedure TForm1.TapiLineCallerID(Sender: ThbTapiLine; Call: ThbTapiCall);
begin
if Call.CallerID.NameAvail then
Label1.Caption := Call.CallerID.Name;
if Call.CallerID.AddressAvail then
Label2.Caption := Call.CallerID.Address;
end;
How to get the current state
of a call
The ThbTapiCall.State
and ThbTapiCall.StateMode
properties indicate the current state of a call. The ThbTapiLine.OnCallState
event will fire each time the state of a call has changed. There are some
more events which will be triggered if the state of a call has changed
(e.g. OnDialing, OnOffering, OnConnected, OnDisconnected).
// uses hbTapi, Tapi;
procedure TForm1.TapiLineCallState(Sender: ThbTapiLine; Call: ThbTapiCall);
begin
case Call.State of
LINECALLSTATE_OFFERING :; // handle offering
LINECALLSTATE_DISCONNECTED :; // handle connected
// -- and so on --
else
end;
end;
// count the current offering calls
function TForm1.Num_OfferingCalls: integer;
var i: integer;
begin
result := 0;
for i := 0 to hbTapiLine1.Calls.Count-1 do
begin
if hbTapiLine1.Calls[i].State = LINECALLSTATE_OFFERING
then
inc(result);
end;
end;
How to become aware of incoming
calls
An incoming call is indicated by fireing the ThbTapiLine.OnOffering
event. The ThbTapiLine.OnCallState
event is fired also. Use the ThbTapiLine.Calls.Count property to become
aware of existing calls on the line device. Check the ThbTapiCall.Alive
property to prove if the call is a "visible" call to the user
or if it's an idle call.
// count the current alive calls on the line
n := 0;
for i := 0 to hbTapiLine1.Calls.Count-1 do
begin
if hbTapiLine1.Calls[i].Alive then
inc(n);
end;
How make a data call
Use the hbTapiLine1.CallParams
properties to define the kind of connection you want to establish. Remember
that you should check, if the selected device
supports data connections.
interface
uses hbTapi, tapi, ...
TForma1.Button1.Click(Sender: TObject);
begin
try
hbTapiLine1.CallParams.MediaMode := LINEMEDIAMODE_DATAMODEM;
hbTapiLine1.MakeCall(Edit1.Text); // phone number
except
on EhbTapiError do
MessageDlg('MakeCall failed!' + E.Message,
mtInformation, [mbOk], 0);
end;
end;
How make make an outgoing
call using a special address
Use the hbTapiLine1.CallParams.AddressID
property to define an address that is to be used for the outgoing call.
interface
uses hbTapi, tapi, ...
TForma1.Button1.Click(Sender: TObject);
begin
try
if hbTapiLine1.Addresses.Count > 1 then
hbTapiLine1.CallParams.AddressID :=
1 // use the second address of the line device
else
hbTapiLine1.CallParams.AddressID :=
0; // use the first address of the line device
hbTapiLine1.MakeCall(Edit1.Text); // phone number
except
on EhbTapiError do
MessageDlg('MakeCall failed!' + E.Message,
mtInformation, [mbOk], 0);
end;
end;