📄 main.pas
字号:
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls, OleCtrls, AMITAPIPROLib_TLB;
type
TFormMain = class(TForm)
MainMenu1: TMainMenu;
File1: TMenuItem;
Readme1: TMenuItem;
Exit1: TMenuItem;
PleaseClickMe1: TMenuItem;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
GroupBox3: TGroupBox;
amTapiPro1: TamTapiPro;
ComboLineName: TComboBox;
TextCallState: TMemo;
TextNumber: TEdit;
CommandClear: TButton;
CommandCall: TButton;
CommandHangUp: TButton;
CommandAnswer: TButton;
procedure Exit1Click(Sender: TObject);
procedure Readme1Click(Sender: TObject);
procedure PleaseClickMe1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure CommandClearClick(Sender: TObject);
procedure amTapiPro1CallerID(Sender: TObject; const Number,
Name: WideString; Flags: Integer);
procedure amTapiPro1CallState(Sender: TObject;
const State: WideString);
procedure CommandCallClick(Sender: TObject);
procedure amTapiPro1DelayedError(Sender: TObject; decType: Integer;
const Description: WideString);
procedure amTapiPro1DigitReceived(Sender: TObject;
const Digit: WideString);
procedure CommandHangUpClick(Sender: TObject);
procedure amTapiPro1Disconnected(Sender: TObject);
procedure amTapiPro1IncomingCall(Sender: TObject; RingNumber: Integer);
procedure amTapiPro1SpecialInfo(Sender: TObject;
const Info: WideString);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure CommandAnswerClick(Sender: TObject);
procedure ComboLineNameChange(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const OWNERCONST = 4;
var
FormMain: TFormMain;
implementation
uses readme;
{$R *.dfm}
procedure TFormMain.Exit1Click(Sender: TObject);
begin
Self.Close;
end;
procedure TFormMain.Readme1Click(Sender: TObject);
begin
FormreadMe.Show;
end;
procedure TFormMain.PleaseClickMe1Click(Sender: TObject);
begin
FormReadMe.Show;
end;
procedure TFormMain.FormCreate(Sender: TObject);
var x: integer;
LineName: String;
begin
amTapiPro1.MediaMode := AUTOMATEDVOICE;
amTapiPro1.CallPrivilege := OWNERCONST; //allows us to answer incoming calls
ComboLineName.Text := 'Select telephony line device';
//Enumerate TAPI Line devices, devices are numbered starting at 0
for X := 0 to amTapiPro1.NumberOfLines - 1 do
begin
//Get the line name numbered i, this will also set the TapiNegotiatedVersion and
//the DevCaps properties to valid values for the line device numbered i
LineName := amTapiPro1.GetLineName(X);
If ((amTapiPro1.TapiNegotiatedVersion > 0) And ((amTapiPro1.DevCaps And AUTOMATEDVOICE) > 0)) then
//If amTapi was able to negotiate a TAPI version and the telephony device selected
//supports AUTOMATEDVOICE
//then add the line device name to the combo
ComboLineName.Items.add(LineName);
end;
end;
procedure TFormMain.CommandClearClick(Sender: TObject);
begin
TextCallState.Text:='';
end;
procedure TFormMain.amTapiPro1CallerID(Sender: TObject; const Number,
Name: WideString; Flags: Integer);
begin
if (Flags And LINECALLPARTYID_NAME) > 0 then TextCallState.SelText := 'Caller Name: ' + Name + #13#10;
if (Flags And LINECALLPARTYID_NUMBER) > 0 then TextCallState.SelText := 'Caller Number: ' + Number + #13#10;
if (Flags And LINECALLPARTYID_BLOCKED) > 0 then TextCallState.SelText := 'Caller ID blocked' + #13#10;
if (Flags And LINECALLPARTYID_OUTOFAREA) > 0 then TextCallState.SelText := 'Caller out of area' + #13#10;
if (Flags And LINECALLPARTYID_UNKNOWN) > 0 then TextCallState.SelText := 'Caller ID unknown' + #13#10;
if (Flags And LINECALLPARTYID_PARTIAL) > 0 then TextCallState.SelText := 'Caller ID partial' + #13#10;
if (Flags And LINECALLPARTYID_UNAVAILABLE) > 0 then TextCallState.SelText := 'Caller ID unavailable' + #13#10;
end;
procedure TFormMain.amTapiPro1CallState(Sender: TObject;
const State: WideString);
begin
//Display the Call state message
TextCallState.SelText := State + #13#10;
//Add case statements as required, see help file for possible values
if State = 'BUSY' then
//Some telephony devices do not automatically transition to Disconnected so hangup
CommandCallClick(self);
end;
procedure TFormMain.CommandCallClick(Sender: TObject);
begin
//Make the call, will generate error if line not open or telephony device busy
amTapiPro1.MakeCall(TextNumber.Text);
end;
procedure TFormMain.amTapiPro1DelayedError(Sender: TObject;
decType: Integer; const Description: WideString);
begin
//This event will fire if an error occurs that TAPI was not able to raise at the time a method was called
//the decType indicates the method that was called that caused the error, the description
//is the actual error message raised by TAPI
//You may not want to use MsgBoxes they will hold up your automatic program
Case decType of
ANSWER_ERROR: ShowMessage ('Delayed Answer error. ' + Description);
DIAL_ERROR:ShowMessage ('Delayed Dialing error. ' + Description);
GENERATE_DIGITS_ERROR: ShowMessage ('Delayed Generate digits error. ' + Description);
HANGUP_ERROR: ShowMessage ('Delayed Hangup error. ' + Description);
MAKE_CALL_ERROR: ShowMessage ('Delayed Make call error. ' + Description);
end;
end;
procedure TFormMain.amTapiPro1DigitReceived(Sender: TObject;
const Digit: WideString);
begin
//DTMF touch tone digit received from the remote party
TextCallState.SelText := 'Digit received ' + Digit + #13#10;
end;
procedure TFormMain.CommandHangUpClick(Sender: TObject);
begin
amTapiPro1.HangUp;
end;
procedure TFormMain.amTapiPro1Disconnected(Sender: TObject);
begin
CommandHangUpClick(self);
end;
procedure TFormMain.amTapiPro1IncomingCall(Sender: TObject;
RingNumber: Integer);
begin
TextCallState.SelText := 'Ringing ' + IntToStr(RingNumber) + #13#10;
end;
procedure TFormMain.amTapiPro1SpecialInfo(Sender: TObject;
const Info: WideString);
begin
//SIT tone detected, may need to call HangUp, not all telephony devices will go to Disconnected state automatically
CommandHangUpClick(self);
end;
procedure TFormMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if amTapiPro1.LineOpen then amTapiPro1.LineOpen := False;
end;
procedure TFormMain.CommandAnswerClick(Sender: TObject);
begin
//Answer an incoming call
amTapiPro1.Answer;
end;
procedure TFormMain.ComboLineNameChange(Sender: TObject);
begin
//Close the line (if open) before changing the LineName
if amTapiPro1.LineOpen then amTapiPro1.LineOpen := False;
amTapiPro1.LineName := ComboLineName.Text;
//Open the line, will generate error if telephony device not available
amTapiPro1.LineOpen := True;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -