⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adtapi.pas

📁 测试用例
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    procedure SetTapiLog(const NewLog : TApdTapiLog);
    procedure SetTapiDevices(const Values : TStrings);
    procedure SetSelectedDevice(const NewDevice : string);
    procedure SetEnableVoice(Value: Boolean);
    procedure SetMonitorRecording(const Value : Boolean);
    procedure SetFilterUnsupportedDevices(const Value: Boolean);       

    {Private properties}
    property Open : Boolean
      read FOpen write SetOpen;

    {Event methods}
    procedure TapiStatus(First, Last : Boolean; Device, Message,
      Param1, Param2, Param3 : DWORD);
    procedure TapiLogging(Log : TTapiLogCode);
    procedure TapiPortOpen;
    procedure TapiPortClose;
    procedure TapiConnect;
    procedure TapiFail;
    procedure TapiDTMF(Digit : Char; ErrorCode: LongInt);
    procedure TapiCallerID(ID, IDName: string);
    procedure TapiWave(Msg : TWaveMessage);

    {Overridden protected methods}
    procedure Notification(AComponent : TComponent; Operation: TOperation);
      override;
    procedure Loaded; override;
  public

    {Creation/destruction}
    constructor Create(AOwner : TComponent); override;
      {-Create a TApdTapiDevice component}
    destructor Destroy; override;
      {-Destroy a TApdTapiDevice component}
    procedure Assign(Source: TPersistent); override;
      {-Assign fields from TApdTapiDevice object specified by Source}

    {Public methods}
    procedure Dial(ANumber : string);
      {-Dial ANumber}
    procedure AutoAnswer;
      {-Wait for and answer incoming calls}
    procedure ConfigAndOpen;
      {-Open the TAPI port in passthru mode}
    function CancelCall : Boolean;
      {-Cancel the current call, always returns True}
    procedure CopyCallInfo(var CallInfo : PCallInfo);
      {-Allocate and return a CallInfo structure with current callinfo}
    function GetDevConfig : TTapiConfigRec;
      {-Gets configuration string that can be used with SetDevConfig}
    function MontorTones(const Tones : array of TLineMonitorTones) : LongInt;
      {-Monitor for specific tones }
    procedure SetDevConfig(const Config : TTapiConfigRec);           
      {-Sets config, requires string from GetDevConfig or ShowConfigDialogEdit }
    procedure PlayWaveFile(FileName : string);                         
      {-Play a wave file over the TAPI wave out device }
    procedure StopWaveFile;                                            
      {-Stop the wave file from playing }
    procedure StartWaveRecord;
      {-Start recording a wave data }
    procedure StopWaveRecord;                                          
      {-Stop recording a wave data }
    procedure SaveWaveFile(FileName : string; Overwrite : Boolean);    
      {-Save the recorded wave data to a file }
    procedure SetRecordingParams(NumChannels : Byte;                   
                                 NumSamplesPerSecond : Integer;
                                 NumBitsPerSample : Byte);
      {-Set the parameters used for wave recording. }
    procedure ShowConfigDialog;
      {-Show the TAPI device configuration dialog}
    function ShowConfigDialogEdit
      (const Init : TTapiConfigRec) : TTapiConfigRec;
      {-Show config dlg, returns Get/SetDevConfig compatible string}
    function SelectDevice : TModalResult;
      {-Send a DTMF tone}
    procedure SendTone(Digits : string);

    { following methods added in .06, note that we do not have compatible }
    { test equipment, so there is a chance that this won't work }
    procedure Transfer(aNumber : string);                                {!!.06}
    procedure HoldCall;                                                  {!!.06}
    procedure UnHoldCall;                                                {!!.06}
    
    procedure AutomatedVoicetoComms;
    function  TapiStatusMsg(const Message, State, Reason : DWORD) : string;
    function  FailureCodeMsg(const FailureCode : Integer) : string;    
    function  TranslateAddress(CanonicalAddr : string) : string;
    function  TranslateAddressEx(CanonicalAddr : string;
                                 Flags : LongInt;
                                 var DialableStr : string;
                                 var DisplayableStr : string;
                                 var CurrentCountry : LongInt;
                                 var DestCountry : LongInt;
                                 var TranslateResults : LongInt) : LongInt;
    function  TranslateDialog(CanonicalAddr : string) : Boolean;
    function  TapiLogToString(const LogCode: TTapiLogCode) : string;

    {read-only properties}
    property ApiVersion : LongInt
      read FApiVersion;
    property Attempt : Word
      read FAttempt;
    property BPSRate : DWORD
      read GetBPSRate;
    property CalledID : string                                           {!!.04}
      read GetCalledID;                                                  {!!.04}
    property CalledIDName : string                                       {!!.04}
      read GetCalledIDName;                                              {!!.04}
    property CallerID : string
      read GetCallerID;
    property CallerIDName : string
      read GetCallerIDName;
    property Cancelled : Boolean
      read FCancelled;
    property ComNumber: Integer
      read GetComNumber;
    property Dialing : Boolean
      read FDialing;
    property FailureCode : Integer                                     
      read FFailCode;
    property WaitingForCall : Boolean                                    {!!.04}
      read FWaitingForCall;                                              {!!.04}

  public
    property TapiDevices : TStrings
      read FTapiDevices write SetTapiDevices;
    property SelectedDevice : string
      read FSelectedDevice write SetSelectedDevice;
    property ComPort : TApdCustomComPort
      read FComPort write FComPort;
    property StatusDisplay : TApdAbstractTapiStatus
      read FStatusDisplay write SetStatusDisplay;
    property TapiLog : TApdTapiLog
      read FTapiLog write SetTapiLog;
    property AnswerOnRing : Byte
      read FAnsRings write FAnsRings default DefAnsRings;
    property MaxAttempts : Word
      read FMaxAttempts write FMaxAttempts default DefMaxAttempts;
    property RetryWait : Word
      read FRetryWait write FRetryWait default DefRetryWait;
    property ShowTapiDevices : Boolean
      read FShowTapiDevices write FShowTapiDevices;
    property ShowPorts : Boolean
      read FShowPorts write FShowPorts;
    property EnableVoice : Boolean
      read FEnableVoice write SetEnableVoice;
    property InterruptWave : Boolean
      read FInterruptWave write FInterruptWave;
    property UseSoundCard : Boolean
      read FUseSoundCard write FUseSoundCard;
    property TrimSeconds : Byte
      read FTrimSeconds write FTrimSeconds;
    property SilenceThreshold : Integer
      read FSilenceThreshold write FSilenceThreshold;
    property MonitorRecording : Boolean
      read FMonitorRecording write SetMonitorRecording;
    property ParentHWnd : HWnd
      read GetParentHWnd write FParentHWnd;
    property FilterUnsupportedDevices : Boolean
      read FFilterUnsupportedDevices write SetFilterUnsupportedDevices
      default True;

    {Read-only properties}
    property Number : string
      read FNumber;
    property DeviceCount : DWORD
      read FDeviceCount;
    property TapiState : TTapiState
      read GetTapiState;                                        
    property WaveFileName : TFileName                                  
      read FWaveFileName;                                              
    property MaxMessageLength : LongInt                                
      read FMaxMessageLength write FMaxMessageLength                   
      default DefMaxMessageLength;                                     
    property WaveState : TWaveState                                    
      read FWaveState;
    property AvgWaveInAmplitude : Integer                              
      read FAvgWaveInAmplitude;                                        

    {events}
    property OnTapiStatus : TTapiStatusEvent
      read FOnTapiStatus write FOnTapiStatus;
    property OnTapiLog : TTapiLogEvent
      read FOnTapiLog write FOnTapiLog;
    property OnTapiPortOpen : TNotifyEvent
      read FOnTapiPortOpen write FOnTapiPortOpen;
    property OnTapiPortClose : TNotifyEvent
      read FOnTapiPortClose write FOnTapiPortClose;
    property OnTapiConnect : TNotifyEvent
      read FOnTapiConnect write FOnTapiConnect;
    property OnTapiFail : TNotifyEvent
      read FOnTapiFail write FOnTapiFail;
    property OnTapiDTMF : TTapiDTMFEvent                               
      read FOnTapiDTMF write FOnTapiDTMF;                              
    property OnTapiCallerID : TTapiCallerIDEvent                       
      read FOnTapiCallerID write FOnTapiCallerID;
    property OnTapiWaveNotify : TTapiWaveNotify
      read FOnTapiWaveNotify write FOnTapiWaveNotify;
    property OnTapiWaveSilence : TTapiWaveSilence
      read FOnTapiWaveSilence write FOnTapiWaveSilence;
  end;

  {Builtin log procedure}
  TApdTapiLog = class(TApdBaseComponent)
  protected {private}
    {.Z+}
    FTapiHistoryName : string;
    FTapiDevice      : TApdCustomTapiDevice;

    procedure Notification(AComponent : TComponent;
                           Operation: TOperation); override;

  public
    constructor Create(AOwner : TComponent); override;
    destructor Destroy; override;
      {-Create a TApdTapiLog component}
    {.Z-}
    procedure UpdateLog(const Log : TTapiLogCode); virtual;
      {-Add a log entry}

  published
    property TapiHistoryName : string
      read FTapiHistoryName write FTapiHistoryName;
    property TapiDevice : TApdCustomTapiDevice
      read FTapiDevice write FTapiDevice;
  end;

  {Abstract protocol status class}
  TApdAbstractTapiStatus = class(TApdBaseComponent)
  protected {private}
    {.Z+}
    FAnswering       : Boolean;
    FCaption         : TCaption;                                       
    FCtl3D           : Boolean;
    FDisplay         : TForm;
    FPosition        : TPosition;
    FVisible         : Boolean;

    procedure Notification(AComponent : TComponent;
                           Operation: TOperation); override;

  protected
    FTapiDevice      : TApdCustomTapiDevice;

    procedure SetPosition(const NewPosition : TPosition);
    procedure SetCtl3D(const NewCtl3D : Boolean);
    procedure SetVisible(const NewVisible : Boolean);
    procedure SetCaption(const NewCaption : TCaption);
    procedure GetProperties;
    procedure Show;

  public
    constructor Create(AOwner : TComponent); override;
      {-Create a TApdAbstractTapiStatus component}
    destructor Destroy; override;
      {-Destroy a TApdAbstractTapiStatus component}
    {.Z-}
    procedure UpdateDisplay(First, Last : Boolean; Device, Message,
      Param1, Param2, Param3 : DWORD); virtual; abstract;
      {-Update the status display with current data}
    procedure CreateDisplay; dynamic; abstract;
      {-Create the status display}
    procedure DestroyDisplay; dynamic; abstract;
      {-Destroy the status display}

    property Answering : Boolean
      read FAnswering write FAnswering;                            
    property Display : TForm
      read FDisplay write FDisplay;
  published
    property Position : TPosition
      read FPosition write SetPosition;
    property Ctl3D : Boolean
      read FCtl3D write SetCtl3D;
    property Visible : Boolean
      read FVisible write SetVisible;
    property TapiDevice : TApdCustomTapiDevice
      read FTapiDevice write FTapiDevice;
    property Caption : TCaption
      read FCaption write SetCaption;                                  
  end;

  {TAPI component}
  TApdTapiDevice = class(TApdCustomTapiDevice)
  published
    {properties}
    property SelectedDevice;
    property ComPort;
    property StatusDisplay;
    property TapiLog;
    property AnswerOnRing;
    property RetryWait;
    property MaxAttempts;
    property ShowTapiDevices;
    property ShowPorts;                                                
    property EnableVoice;
    property FilterUnsupportedDevices;                                 

    {events}
    property OnTapiStatus;
    property OnTapiLog;
    property OnTapiPortOpen;
    property OnTapiPortClose;
    property OnTapiConnect;
    property OnTapiFail;
    property OnTapiDTMF;                                               
    property OnTapiCallerID;                                           
    property OnTapiWaveNotify;
    property OnTapiWaveSilence;
  end;

implementation

const                                                                  
  {event types}
  etTapiConnect    = 0;                                                
  etTapiPortOpen   = 1;
  etTapiPortClose  = 2;                                                
  etTapiFail       = 3;                                                
  etTapiLineCreate = 4;                                                


var
  OldCursor : HCursor;

{General purpose routines}

  function TapiErrorCode(ErrorCode : LongInt) : LongInt;
    {-Return an APW error code from a TAPI error code}
  begin
    if ErrorCode = 0  then
      Result := 0
    else
      Result := (ErrorCode and $7FFFFFFF) + TapiErrorBase;
  end;

  procedure TapiException(const Ctl : TComponent;
                          const Res : LongInt);
    {-Decode the TAPI result and call CheckException}
  begin
    CheckException(Ctl, -TapiErrorCode(Res));
  end;

  procedure WaitCursor;
    {-Set hourglass cursor}
  begin
    OldCursor := SetCursor(LoadCursor(0, idc_Wait));
  end;

  procedure RestoreCursor;
    {-Remove hourglass cursor and restore old}
  begin
    SetCursor(OldCursor);
  end;

{TApdTapiLog}

  procedure TApdTapiLog.Notification(AComponent : TComponent;
                                     Operation: TOperation);
  begin
    inherited Notification(AComponent, Operation);

    if Operation = opRemove then begin

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -