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

📄 adfax.pas

📁 测试用例
💻 PAS
📖 第 1 页 / 共 5 页
字号:
(***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is TurboPower Async Professional
 *
 * The Initial Developer of the Original Code is
 * TurboPower Software
 *
 * Portions created by the Initial Developer are Copyright (C) 1991-2002
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * ***** END LICENSE BLOCK ***** *)

{*********************************************************}
{*                    ADFAX.PAS 4.06                     *}
{*********************************************************}
{* TApdAbstractFax, TApdSendFax, TApdReceiveFax, status  *}
{* and log components                                    *}
{*********************************************************}
{* These components are wrappers to the low-level fax    *}
{* code found in the AwFax and AwAbsFax units.           *}
{*********************************************************}

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

{Options required for this unit}
{$I+,G+,X+,F+,V-,J+}
{$C MOVEABLE,DEMANDLOAD,DISCARDABLE}

unit AdFax;
  {-Fax send/receive components}

interface

uses         
  WinTypes,
  WinProcs,
  SysUtils,
  Classes,
  Messages,
  Controls,
  Graphics,
  Forms,
  OoMisc,
  AwUser,
  AwAbsFax,
  AwFax,
  AwFaxCvt,
  AdExcept,
  AdPort,
  AdTapi,
  AdTUtil;

type
  {Fax classes}
  TFaxClass = (fcUnknown, fcDetect, fcClass1, fcClass2, fcClass2_0);
  TFaxClassSet = set of TFaxClass;

  {$IFNDEF AProBCB}
  {For passing strings in event handlers}
  {TPassString = String[255];} {moved to OOMisc}                         {!!.04}
  {$ENDIF}

  {Definition moved to OOMisc.pas}                                       {!!.04}
  (*TFaxLogCode = TLogFaxCode;(
    lfaxNone,               {none}
    lfaxTransmitStart,      {transmit started}
    lfaxTransmitOk,         {transmit finished okay}
    lfaxTransmitFail,       {transmit failed}
    lfaxReceiveStart,       {receive started}
    lfaxReceiveOk,          {receive finished okay}
    lfaxReceiveSkip,        {receive skipped on request}
    lfaxReceiveFail);       {receive failed}*)

  {General fax event handlers}
  TFaxStatusEvent = procedure(CP : TObject; First, Last : Boolean) of object;
  TFaxLogEvent    = procedure(CP : TObject; LogCode : TFaxLogCode) of object;
  TFaxErrorEvent  = procedure(CP : TObject; ErrorCode : Integer) of object;
  TFaxFinishEvent = procedure(CP : TObject; ErrorCode : Integer) of object;

  {Receive fax event handlers}
  TFaxAcceptEvent = procedure(CP : TObject; var Accept : Boolean) of object;
  TFaxNameEvent   = procedure(CP : TObject; var Name : TPassString) of object;

  {Transmit fax event handlers}
  TFaxNextEvent   = procedure(CP : TObject;
                              var APhoneNumber : TPassString;
                              var AFaxFile : TPassString;
                              var ACoverFile : TPassString) of object;

  {Modem command string}
  {$IFDEF AproBCB}                                                       {!!.02}
  { BCB doesn't like specific length strings in it's properties }        {!BCB6}
  TModemString = String;                                                 {!!.02}
  TStationID   = String;                                                 {!!.02}
  {$ELSE}                                                                {!!.02}
  TModemString = String[40];
  TStationID   = String[20];
  {$ENDIF}                                                               {!!.02}

  {Fax send/receive mode}
  TFaxMode = (fmNone, fmSend, fmReceive);

  {Automatic Fax naming modes}
  TFaxNameMode = (fnNone, fnCount, fnMonthDay);

const
  {Defaults for fax log}
  adfDefFaxHistoryName     = 'APROFAX.HIS';

  {Defaults for TApdCustomAbstractFax properties}
  adfDefInitBaud       = 0;
  adfDefNormalBaud     = 0;
  adfDefFaxClass       = fcDetect;
  adfDefAbortNoConnect = False;
  adfDefExitOnError    = False;
  adfDefSoftwareFlow   = False;
  adfDefFaxStatusInterval = 1;        {in seconds}
  adfDefDesiredBPS     = 9600;
  adfDefDesiredECM     = False;

  {Defaults for TApdReceiveFax properties}
  adfDefAnswerOnRing   = 1;
  adfDefFaxAndData     = False;
  adfDefOneFax         = False;
  adfDefConstantStatus = False;
  adfDefSafeMode       = True;
  adfDefFaxFileExt     = 'APF';

  {Defaults for TApdSendFax properties}
  adfDefBlindDial      = False;
  adfDefDetectBusy     = True;                                         
  adfDefToneDial       = True;
  adfDefDialWait       = 60;       {in seconds}
  adfDefDialAttempts   = 3;
  adfDefDialRetryWait  = 60;       {in seconds}
  adfDefMaxSendCount   = 50;
  adfDefBufferMinimum  = 1000;
  adfDefFaxNameMode    = fnCount;
  adfDefDestinationDir = '';

type
  {Forwards}
  TApdAbstractFaxStatus = class;
  TApdFaxLog = class;

  {Custom abstract fax component}
  TApdCustomAbstractFax = class(TApdBaseComponent)
  protected
    {Private}
    Fax          : PFaxRec;      {Data structure for send/receive}
    FaxMode      : TFaxMode;     {Sending or receiving?}
    MsgHandler   : HWnd;         {Fax message window}
    PrepProc     : TFaxPrepProc; {Procedure for preparing to fax}
    FaxFunc      : TFaxFunc;     {Function for fax session}
    FWaitForTapi : Boolean;      {Flag indicating that we're waiting for TAPI}
    FTapiPrepared: Boolean;      {Flag indicating we're hooked into TAPI events}{!!.04}
    FUserOnTapiPortOpen : TNotifyEvent;   {the TapiDevice.OnTapiPortOpen event}
    FUserOnTapiPortClose : TNotifyEvent;  {the TapiDevice.OnTapiPortClose event}
    FUserOnTapiStatus : TTapiStatusEvent; {the TapiDevice.OnTapiStatus event}

    {General}
    FModemModel    : TPassString;  {Modem model string}
    FModemChip     : TPassString;  {Modem chip string}
    FModemRevision : TPassString;  {Modem revision string}
    FModemBPS      : LongInt;      {Highest BPS supported by modem}
    FCorrection    : Boolean;      {True if modem supports ECM}
    FComPort       : TApdCustomComport;     {ComPort component}
    FTapiDevice    : TApdCustomTapiDevice;  {TapiDevice component}
    FStatusDisplay : TApdAbstractFaxStatus; {Status component}
    FFaxLog        : TApdFaxLog;            {Logging component}
    FFaxFile       : TPassString;           {Fax file name}
    FSupportedFaxClasses :TFaxClassSet;     {Holds supported class info}

    {Internal}
    FVersion       : Integer;
    FTempFile      : TPassString;                
    FStartTime     : DWORD;

    {Events}
    FOnFaxStatus   : TFaxStatusEvent;
    FOnFaxLog      : TFaxLogEvent;
    FOnFaxError    : TFaxErrorEvent;
    FOnFaxFinish   : TFaxFinishEvent;

    {Property get/set methods}
    function GetElapsedTime: DWORD;                                    
    function GetFaxFile : TPassString; virtual;
    procedure SetFaxFile(const NewFile : TPassString); virtual;
    function GetInitBaud : Integer;
    procedure SetInitBaud(const NewBaud : Integer);
    function GetInProgress: Boolean;                                   
    function GetNormalBaud : Integer;
    procedure SetNormalBaud(const NewBaud : Integer);
    function GetFaxClass : TFaxClass;
    procedure SetFaxClass(const NewClass : TFaxClass);
    function GetModemInit : TModemString;
    procedure SetModemInit(const NewInit : TModemString);
    function GetStationID : TStationID;
    procedure SetStationID(const NewID : TStationID);
    procedure SetComPort(const NewPort : TApdCustomComPort);
    procedure SetStatusDisplay(const NewDisplay : TApdAbstractFaxStatus);
    procedure SetFaxLog(const NewLog : TApdFaxLog);
    function GetRemoteID : TStationID;
    function GetSupportedFaxClasses : TFaxClassSet;
    function GetFaxProgress : Word;
    function GetFaxError : Integer;
    function GetSessionBPS : Word;
    function GetSessionResolution : Boolean;
    function GetSessionWidth : Boolean;
    function GetSessionECM : Boolean;
    function GetHangupCode : Word;
    function GetLastPageStatus : Boolean;
    function GetModemModel : TPassString;
    function GetModemRevision : TPassString;
    function GetModemChip : TPassString;
    function GetModemBPS : LongInt;
    function GetModemECM : Boolean;
    function GetTotalPages : Word;
    function GetCurrentPage : Word;
    function GetBytesTransferred : LongInt;
    function GetPageLength : LongInt;
    function GetAbortNoConnect : Boolean;
    procedure SetAbortNoConnect (NewValue : Boolean);
    function GetExitOnError : Boolean;
    procedure SetExitOnError(NewValue : Boolean);
    function GetSoftwareFlow : Boolean;
    procedure SetSoftwareFlow(NewValue : Boolean);
    function GetStatusInterval : Word;
    procedure SetStatusInterval(NewValue : Word);
    function GetDesiredBPS : Word;
    procedure SetDesiredBPS(NewBPS : Word);
    function GetDesiredECM : Boolean;
    procedure SetDesiredECM(NewECM : Boolean);
    function GetFaxFileExt : TPassString;
    procedure SetFaxFileExt(const NewExt : TPassString);

    {Private methods}
    procedure CheckPort;
    procedure CreateFaxMessageHandler;
    procedure Notification(AComponent : TComponent;
                           Operation : TOperation); override;

    procedure PrepareTapi; virtual;
    procedure UnprepareTapi; virtual;
    procedure OpenTapiPort;
    procedure CloseTapiPort;
    procedure WaitForTapi;                                               {!!.04}
    {TapiDevice event handlers}
    procedure FaxTapiPortOpenClose(Sender : TObject);

    procedure Loaded; override;
    procedure ReadVersionCheck(Reader : TReader);
    procedure WriteVersionCheck(Writer : TWriter);
    procedure DefineProperties(Filer : TFiler); override;

    {Event methods}
    procedure apwFaxStatus(CP : TObject; First, Last : Boolean); virtual;
    procedure apwFaxLog(CP : TObject; LogCode : TFaxLogCode); virtual;
    procedure apwFaxError(CP : TObject; ErrorCode : Integer); virtual;
    procedure apwFaxFinish(CP : TObject; ErrorCode : Integer); virtual;

  public {published later}
    property InitBaud : Integer
      read GetInitBaud write SetInitBaud default adfDefInitBaud;
    property NormalBaud : Integer
      read GetNormalBaud write SetNormalBaud default adfDefNormalBaud;
    property FaxClass : TFaxClass
      read GetFaxClass write SetFaxClass default adfDefFaxClass;
    property ModemInit : TModemString
      read GetModemInit write SetModemInit;
    property StationID : TStationID
      read GetStationID write SetStationID;
    property ComPort : TApdCustomComPort
      read FComPort write SetComPort;
    property TapiDevice : TApdCustomTapiDevice
      read FTapiDevice write FTapiDevice;
    property StatusDisplay : TApdAbstractFaxStatus
      read FStatusDisplay write SetStatusDisplay;
    property FaxLog : TApdFaxLog
      read FFaxLog write SetFaxLog;
    property FaxFile : TPassString
      read GetFaxFile write SetFaxFile;
    property AbortNoConnect : Boolean
      read GetAbortNoConnect write SetAbortNoConnect default adfDefAbortNoConnect;
    property ExitOnError : Boolean
      read GetExitOnError write SetExitOnError default adfDefExitOnError;
    property SoftwareFlow : Boolean
      read GetSoftwareFlow write SetSoftwareFlow default adfDefSoftwareFlow;
    property StatusInterval : Word
      read GetStatusInterval write SetStatusInterval default adfDefFaxStatusInterval;
    property DesiredBPS : Word
      read GetDesiredBPS write SetDesiredBPS default adfDefDesiredBPS;
    property DesiredECM : Boolean
      read GetDesiredECM write SetDesiredECM default adfDefDesiredECM;
    property FaxFileExt : TPassString
      read GetFaxFileExt write SetFaxFileExt;

    {Fax events}
    property OnFaxStatus : TFaxStatusEvent
      read FOnFaxStatus write FOnFaxStatus;
    property OnFaxLog : TFaxLogEvent
      read FOnFaxLog write FOnFaxLog;
    property OnFaxError : TFaxErrorEvent
      read FOnFaxError write FOnFaxError;
    property OnFaxFinish : TFaxFinishEvent
      read FOnFaxFinish write FOnFaxFinish;

 public
    {Runtime, readonly properties}
    property SupportedFaxClasses : TFaxClassSet
      read GetSupportedFaxClasses;
    property FaxProgress : Word
      read GetFaxProgress;
    property FaxError : Integer
      read GetFaxError;
    property SessionBPS : Word
      read GetSessionBPS;
    property SessionResolution : Boolean
      read GetSessionResolution;
    property SessionWidth : Boolean
      read GetSessionWidth;
    property SessionECM : Boolean
      read GetSessionECM;
    property HangupCode : Word
      read GetHangupCode;
    property LastPageStatus : Boolean
      read GetLastPageStatus;
    property ModemModel : TPassString
      read GetModemModel;
    property ModemRevision: TPassString
      read GetModemRevision;
    property ModemChip : TPassString
      read GetModemChip;
    property ModemBPS : LongInt
      read GetModemBPS;
    property ModemECM : Boolean
      read GetModemECM;
    property TotalPages : Word
      read GetTotalPages;
    property CurrentPage : Word
      read GetCurrentPage;
    property BytesTransferred : LongInt
      read GetBytesTransferred;
    property PageLength : LongInt
      read GetPageLength;
    property RemoteID : TStationID
      read GetRemoteID;
    property ElapsedTime : DWORD
      read GetElapsedTime;
    property InProgress : Boolean
      read GetInProgress;

    {Creation/destruction}
    constructor Create(AOwner : TComponent); override;
      {-Create a TApdAbstractFax component}
    destructor Destroy; override;
      {-Destroy a tApdAbstractFax component}

    {General}
    procedure CancelFax;
      {-Cancel the fax session}
    function StatusMsg(const Status : Word) : TPassString;
      {-Return a status message for Status}
    function LogMsg(const LogCode : TFaxLogCode) : string;               {!!.04}
      {-Return a string describing the log code }
  end;

  {Abstract fax status class}
  TApdAbstractFaxStatus = class(TApdBaseComponent)
  protected {private}
    {.Z+}
    FDisplay         : TForm;
    FPosition        : TPosition;

⌨️ 快捷键说明

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