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

📄 复件 adtsel_my.pas

📁 自动语音应答系统
💻 PAS
字号:
{*********************************************************}
{*                   ADTSEL.PAS 3.01                     *}
{*      Copyright (c) TurboPower Software 1996-2000      *}
{*                 All rights reserved.                  *}
{*********************************************************}

{Global defines potentially affecting this unit}
{$I AWDEFINE.INC}

{Options required for this unit}
{$G+,X+,F+}

unit AdTSel_My;
  {-Property editor, end-user dialog for selecting TAPI devices or ports}

interface
   
uses
  WinProcs,
  WinTypes,
  Messages,
  SysUtils,
  Classes,
  Controls,
  Forms,registry,
  Dialogs,
  StdCtrls,
  Buttons,
  AwUser,
  AdPort,
  AdExcept,
  AdTUtil,
  OOMisc,
  AdSelCom,AdTapi,
  {$IFDEF Win32}
  AwWin32, ExtCtrls;
  {$ELSE}
  AwComm;
  {$ENDIF}

  function SelectDevice_My(ApdTapiDevice:TApdTapiDevice;wait:boolean;RegPath:string) : TModalResult;

type
  TDeviceSelectionForm_My = class(TForm)
    dsfComboBox    : TComboBox;
    dsfOkBitBtn    : TBitBtn;
    dsfCancelBitBtn: TBitBtn;
    Timer1: TTimer;

    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure dsfOkBitBtnClick(Sender: TObject);
    procedure dsfCancelBitBtnClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
    FPortItemList    : TStringList;
    FTapiMode        : TTapiMode;
    FComNumber       : Word;
    FDeviceName      : string;
    FShowTapiDevices : Boolean;
    FShowPorts       : Boolean;                                  
    FEnumerated      : Boolean;
  public
    { Public declarations }
    RegPath:string;
    wait:boolean;
    procedure EnumComPorts;
    procedure EnumTapiPorts;
    procedure EnumAllPorts;

    constructor Create(AOwner : TComponent); override;
    property PortItemList : TStringList
      read FPortItemList write FPortItemList;
    property TapiMode : TTapiMode
      read FTapiMode write FTapiMode;
    property ComNumber : Word
      read FComNumber write FComNumber;
    property DeviceName : string
      read FDeviceName write FDeviceName;
    property ShowTapiDevices : Boolean
      read FShowTapiDevices write FShowTapiDevices;
    property ShowPorts : Boolean
      read FShowPorts write FShowPorts;                           
  end;

const
  DirectTo = 'Direct to COM';

var
  DeviceSelectionForm_My: TDeviceSelectionForm_My;

implementation


{$R *.DFM}

  function SelectDevice_My(ApdTapiDevice:TApdTapiDevice;wait:boolean;RegPath:string) : TModalResult;
    {-Show the TAPI device selection dialog}
  var
    E : TDeviceSelectionForm_My;
  begin
    E := TDeviceSelectionForm_My.Create(Application);
    E.ShowTapiDevices := ApdTapiDevice.ShowTapiDevices;
    E.ShowPorts := ApdTapiDevice.ShowPorts;
    E.TapiMode := tmAuto;
    if (ApdTapiDevice.ComPort <> nil) then
      E.TapiMode := ApdTapiDevice.ComPort.TapiMode;

    if E.TapiMode = tmOff then begin
      E.ComNumber := ApdTapiDevice.ComPort.ComNumber;
    end else begin
      E.DeviceName := ApdTapiDevice.SelectedDevice;
    end;
    E.wait:=wait;
    E.RegPath:=RegPath;
    
    try
      if E.ShowModal = mrOK then begin
        if (ApdTapiDevice.ComPort <> nil) and (E.TapiMode = tmOff) then begin
          ApdTapiDevice.ComPort.TapiMode := E.TapiMode;
          ApdTapiDevice.ComPort.ComNumber := E.ComNumber;
        end else if (E.TapiMode <> tmOff) then begin
          if (ApdTapiDevice.ComPort <> nil) then
            ApdTapiDevice.ComPort.TapiMode := E.TapiMode;

          {Raise exception if 16-bit app and TAPI not enabled}
          {$IFNDEF Win32}
          {$IFNDEF EnableTapi16}
          raise ETapi16Disabled.Create(ecTapi16Disabled, True);
          {$ENDIF}
          {$ENDIF}

          {Set the selected TAPI device}
          ApdTapiDevice.SelectedDevice := E.DeviceName;

          {Check for DTMF Compatibility if enabled}
          ApdTapiDevice.EnableVoice:=ApdTapiDevice.EnableVoice;
        end;
        Result := mrOK;
      end else
        Result := mrCancel;
    finally
      E.Free;
    end;
  end;

procedure TempCallback(Device   : LongInt;
                       Message  : LongInt;
                       Instance : LongInt;
                       Param1   : LongInt;
                       Param2   : LongInt;
                       Param3   : Longint);
{$IFDEF Win32} stdcall; {$ELSE} export; {$ENDIF}
begin
end;

constructor TDeviceSelectionForm_My.Create(AOwner : TComponent);
begin
  inherited Create(AOwner);
  FEnumerated      := False;
end;

procedure TDeviceSelectionForm_My.FormCreate(Sender: TObject);
begin
  FTapiMode := tmAuto;
  FPortItemList := TStringList.Create;
end;

procedure TDeviceSelectionForm_My.EnumComPorts;
var
  Loop      : Word;
begin
  for Loop := 1 to MaxComHandles do begin                        
    if IsPortAvailable(Loop) then
      FPortItemList.Add(DirectTo+IntToStr(Loop));
    Application.ProcessMessages;
  end;
end;

procedure TDeviceSelectionForm_My.EnumTapiPorts;
var
  I          : Word;
  Count      : DWORD;
  LineApp    : TLineApp;
  LineExt    : TLineExtensionID;
  ApiVersion : LongInt;
  LineCaps   : PLineDevCaps;
  S          : String;
begin
  {try}
    {Initialize a TAPI line}
    {CheckException(Self,}
    if tuLineInitialize(LineApp,
                                          hInstance,
                                          TempCallback,
                                          '',
                                          Count) = 0 then begin
                                          {);}

    {Enumerate all line devices, add names to the list box}
    for I := 1 to Count do begin
      {Negotiate the API version to use for this device}
      if tuLineNegotiateApiVersion(LineApp, I-1,
                                   TapiHighVer,
                                   TapiHighVer,
                                   ApiVersion,
                                   LineExt) = 0 then begin

        {Get the device capabilities}
        {CheckException(Self,}
        if tuLineGetDevCapsDyn(LineApp,
                                                 I-1,
                                                 ApiVersion,
                                                 0,
                                                 LineCaps) = 0 then begin
                                                 {);}

        {Extract the device name}
        with LineCaps^ do begin
          {$IFDEF Win32}
          SetLength(S, LineNameSize);
          {$IFDEF H+}
          Move(LineCaps^.Data[LineNameOffset], PChar(S)^, LineNameSize);
          {$ELSE}
          Move(LineCaps^.Data[LineNameOffset], S[1], LineNameSize);
          {$ENDIF}
          {$ELSE}
          Move(LineCaps^.Data[LineNameOffset], S[1], LineNameSize);
          S[0] := Char(LineNameSize);
          {$ENDIF}
        end;

        {Free the buffer allocated by LineGetDevCapsDyn}
        FreeMem(LineCaps, LineCaps^.TotalSize);

        {Add the name our list}
        if S <> '' then
          FPortItemList.Add(Copy(S, 1, Length(S)-1))
        else
          FPortItemList.Add('<noname>');
        end;
      end;
 end;
    end;
  (*
  except
    {Ignore errors, just return a blank list}
  end;
  *)

  {Shutdown this line}
  tuLineShutdown(LineApp);
end;

procedure TDeviceSelectionForm_My.EnumAllPorts;
  {-Collect the TAPI devices and comport numbers}
begin
  Screen.Cursor := crHourGlass;

  {Show TAPI devices only if requested}
  if ShowTapiDevices then
    EnumTapiPorts;

  {Show ports only if requested}
  if (ShowPorts) then                                             
    EnumComPorts;

  Screen.Cursor := crDefault;
end;

procedure TDeviceSelectionForm_My.FormDestroy(Sender: TObject);
begin
  if Assigned(FPortItemList) then
    FPortItemList.Free;
end;

procedure TDeviceSelectionForm_My.dsfOkBitBtnClick(Sender: TObject);
var
   reg:tregistry;
begin
  if dsfComboBox.ItemIndex=-1 then exit;
  DeviceName := dsfComboBox.Items[dsfComboBox.ItemIndex];
  if Pos(DirectTo, DeviceName) > 0 then begin
    TapiMode := tmOff;
    ComNumber := StrToInt(Copy(DeviceName, Length(DirectTo)+1, Length(DeviceName)));
  end else begin
    TapiMode := tmAuto;
    ComNumber := 0;
  end;
     reg:=Tregistry.create;
     reg.RootKey:=HKEY_LOCAL_MACHINE;
     reg.OpenKey(regpath,true);
     reg.writestring('Modem',DeviceName);
     reg.closekey;
     reg.free;
  ModalResult := mrOK;
end;

procedure TDeviceSelectionForm_My.dsfCancelBitBtnClick(Sender: TObject);
begin
  ModalResult := mrCancel;
end;

procedure TDeviceSelectionForm_My.FormShow(Sender: TObject);
var
   reg:tregistry;
begin
  if not FEnumerated then begin
    EnumAllPorts;
    dsfComboBox.Items := FPortItemList;

   { Highlite the active device in the list }
    with dsfComboBox do
      if FTapiMode = tmOff then begin
        ItemIndex := Items.IndexOf(DirectTo+IntToStr(ComNumber));
      end else begin
        ItemIndex := Items.IndexOf(FDeviceName);
      end;
    FEnumerated := True;
    if dsfComboBox.ItemIndex < 0 then dsfComboBox.ItemIndex := 0;
  end;
  if not wait then
  begin
     reg:=Tregistry.create;
     reg.RootKey:=HKEY_LOCAL_MACHINE;
     reg.OpenKey(regpath,true);
     if reg.ValueExists('Modem') then
     begin
        dsfComboBox.ItemIndex:=dsfComboBox.Items.IndexOf(reg.ReadString('Modem'));
        if dsfComboBox.ItemIndex<>-1 then
           timer1.enabled:=true;
//        close;
//        ModalResult := mrOK;
     end;
     reg.closekey;
     reg.free;
  end;
end;

procedure TDeviceSelectionForm_My.Timer1Timer(Sender: TObject);
begin
    dsfOkBitBtnClick(Sender);
end;

end.

⌨️ 快捷键说明

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