📄 addial.pas
字号:
(***** 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 ***** *)
{*********************************************************}
{* ADDIAL.PAS 4.06 *}
{*********************************************************}
{* Deprecated modem dialer dialog *}
{*********************************************************}
{Global defines potentially affecting this unit}
{$I AWDEFINE.INC}
{Options required for this unit}
{$G+,X+,F-,V-,P-,T-,B-}
unit AdDial;
{-Dialer window}
interface
uses
SysUtils,
WinTypes,
WinProcs,
Messages,
Classes,
Graphics,
Controls,
Forms,
Dialogs,
StdCtrls,
Buttons,
OoMisc,
AwModem,
AdExcept,
AdPort,
AdModem;
type
{TApdModemDialer options}
TDialerOption = (mdAbortOnVoice, mdAbortOnBusy, mdAbortOnNoCarrier,
mdAbortOnNoDialtone, mdAbortOnError);
TDialerOptions = Set of TDialerOption;
TDialResult = (drNone, drDialing, drConnected, drAborted);
const
{Prompt/label base used to translate ddXxx values to string IDs}
DialerDialogBase = 4300;
ddCycling = 4301; {dialer is cycling}
ddRetryWaiting = 4302; {waiting to retry}
ddRetryWaitOver = 4303; {wait for retry over, about to dial}
ddDialing = 4304; {dialing and counting down}
ddModemConnect = 4305; {connection established}
ddModemConnectAt = 4306; {connection established at known baud rate}
ddModemVoice = 4307; {remote answered with voice}
ddModemError = 4308; {modem returned an ERROR}
ddModemNoCarrier = 4309; {modem returned NO CARRIER}
ddModemBusy = 4310; {modem received busy signal}
ddModemNoDialTone = 4311; {modem did not find dial tone}
ddDialTimedOut = 4312; {dial attempt timed out}
{TApdModemDialer settings}
addDefDialerOptions = [mdAbortOnNoDialtone, mdAbortOnError];
{TApdDialerDialog settings}
NumStatusLines = 13;
addDefMaxDialTries = 10;
addDefRetrySecs = 60;
type
{component for dialing phone numbers}
TApdCustomModemDialer = class(TApdBaseComponent)
protected {private}
{.Z+}
FModem : TApdCustomModem; {modem to use for dialing}
FPhoneNumber : String; {phone number to dial}
FMaxDialTries : Integer; {max # of dial attempts}
FRetrySecs : Integer; {seconds between dial retries}
FDialerOptions : TDialerOptions; {options for dialing}
FDialResult : TDialResult; {result of dial attempt}
FDialing : Boolean; {TRUE if dialer active}
FRetryStart : TNotifyEvent; {before dial retry starts}
FRetryCount : TConnectCountEvent; {when retry counter ticks}
FRetryEnd : TNotifyEvent; {when dial retry is finished}
FCycleDial : TNotifyEvent; {when dial attempt cycled}
FDialStart : TNotifyEvent; {at beginning of dial}
FConnect : TNotifyEvent; {when connection established}
FDialCount : TConnectCountEvent; {when dial timer ticks}
FGotLineSpeed : TLineSpeedEvent; {when connect speed detrmnd}
FBusy : TNotifyEvent; {when modem returns busy}
FVoice : TNotifyEvent; {when modem returns voice}
FError : TNotifyEvent; {when modem returns error}
FNoCarrier : TNotifyEvent; {when modem returns ncarrier}
FNoDialTone : TNotifyEvent; {when modem returns ndialtn}
FDialTimedOut : TNotifyEvent; {when dial attempt times out}
FConnectionEstablished : TNotifyEvent; {when connection is established}
FTooManyTries : TNotifyEvent; {when too many dials tried}
FRetrying : Boolean; {TRUE if retrying dial attempt}
{dialing data}
ComPort : TApdCustomComPort; {communications port}
DialTry : Integer; {current dial try}
DialIdx : Integer; {index of dial start timer trig}
{retry data}
Cycling : Boolean; {TRUE if cycling dial attempt}
RetryIdx : Integer; {index of retry count trigger}
RetryWait : Integer; {# secs left until retry}
{saved event handlers}
SaveTriggerTimer : TTriggerTimerEvent;
SaveModemConnect : TNotifyEvent;
SaveDialCount : TConnectCountEvent;
SaveGotLineSpeed : TLineSpeedEvent;
SaveModemBusy : TNotifyEvent;
SaveModemVoice : TNotifyEvent;
SaveModemError : TNotifyEvent;
SaveModemNoCarrier : TNotifyEvent;
SaveModemNoDialTone : TNotifyEvent;
SaveDialTimedOut : TNotifyEvent;
SaveOnByeBye : TNotifyEvent;
SaveModemIsConnected : TNotifyEvent;
procedure Notification(AComponent : TComponent; Operation : TOperation); override;
procedure PrepareDialing;
{-Start a timer to trigger the beginning of a dial attempt}
procedure RetryDial;
{-Retry the last dial attempt, if possible}
procedure RetryDone;
{-Cleanup after a retry countdown}
{dialer event handlers}
procedure DialerTriggerTimer(Sender : TObject; TriggerHandle : Word);
procedure DialerModemConnect(Sender : TObject);
procedure DialerDialCount(Sender : TObject; Remaining : Word);
procedure DialerGotLineSpeed(Sender : TObject; Speed : LongInt);
procedure DialerModemBusy(Sender : TObject);
procedure DialerModemVoice(Sender : TObject);
procedure DialerModemError(Sender : TObject);
procedure DialerModemNoCarrier(Sender : TObject);
procedure DialerModemNoDialTone(Sender : TObject);
procedure DialerDialTimedOut(Sender : TObject);
procedure DialerModemByeBye(Sender : TObject);
procedure DialerModemIsConnected(Sender : TObject);
procedure RetryStart; virtual;
procedure RetryCount; virtual;
procedure RetryEnd; virtual;
procedure CycleDial; virtual;
procedure DialStart; virtual;
procedure GotConnect; virtual;
procedure DialCount(Cnt : Cardinal); virtual;
procedure GotLineSpeed(Speed : LongInt); virtual;
procedure GotBusy; virtual;
procedure GotVoice; virtual;
procedure GotError; virtual;
procedure GotNoCarrier; virtual;
procedure GotNoDialTone; virtual;
procedure DialTimedOut; virtual;
procedure ConnectionEstablished; virtual;
procedure TooManyTries; virtual;
procedure SinkHooks;
{-Replace existing ComPort/Modem event handlers with dialer handlers}
procedure RemoveHooks;
{-Remove dialer event handlers and replace with originals}
procedure DialingFinished;
{-Dialing done: shut down dial attempt}
procedure ShutDownOnDestroy;
{-Clean up during the middle of a dial attempt}
public
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
{.Z-}
{dialing data}
property Modem : TApdCustomModem
read FModem write FModem;
property PhoneNumber : String
read FPhoneNumber write FPhoneNumber;
property MaxDialTries : Integer
read FMaxDialTries write FMaxDialTries default addDefMaxDialTries;
property RetrySecs : Integer
read FRetrySecs write FRetrySecs default addDefRetrySecs;
property DialerOptions : TDialerOptions
read FDialerOptions write FDialerOptions;
property DialResult : TDialResult
read FDialResult;
property Dialing : Boolean
read FDialing;
property Retrying : Boolean
read FRetrying;
{events}
property OnRetryStart : TNotifyEvent
read FRetryStart write FRetryStart;
property OnRetryCount : TConnectCountEvent
read FRetryCount write FRetryCount;
property OnRetryEnd : TNotifyEvent
read FRetryEnd write FRetryEnd;
property OnCycleDial : TNotifyEvent
read FCycleDial write FCycleDial;
property OnDialStart : TNotifyEvent
read FDialStart write FDialStart;
property OnConnect : TNotifyEvent
read FConnect write FConnect;
property OnDialCount : TConnectCountEvent
read FDialCount write FDialCount;
property OnGotLineSpeed : TLineSpeedEvent
read FGotLineSpeed write FGotLineSpeed;
property OnBusy : TNotifyEvent
read FBusy write FBusy;
property OnVoice : TNotifyEvent
read FVoice write FVoice;
property OnError : TNotifyEvent
read FError write FError;
property OnNoCarrier : TNotifyEvent
read FNoCarrier write FNoCarrier;
property OnNoDialTone : TNotifyEvent
read FNoDialTone write FNoDialTone;
property OnDialTimedOut : TNotifyEvent
read FDialTimedOut write FDialTimedOut;
property OnConnectionEstablished : TNotifyEvent
read FConnectionEstablished write FConnectionEstablished;
property OnTooManyTries : TNotifyEvent
read FTooManyTries write FTooManyTries;
{methods}
procedure Dial;
procedure Cycle;
procedure Extend(const ByHowMuch : Cardinal);
procedure Abort;
end;
TApdModemDialer = class(TApdCustomModemDialer)
{dialing data}
property Modem;
property PhoneNumber;
property MaxDialTries;
property RetrySecs;
property DialerOptions;
{events}
property OnRetryStart;
property OnRetryCount;
property OnRetryEnd;
property OnCycleDial;
property OnDialStart;
property OnConnect;
property OnDialCount;
property OnGotLineSpeed;
property OnBusy;
property OnVoice;
property OnError;
property OnNoCarrier;
property OnNoDialTone;
property OnConnectionEstablished;
property OnTooManyTries;
end;
{.Z+}
TDialerForm = class(TForm)
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
CycleBtn: TBitBtn;
ExtendBtn: TBitBtn;
AbortBtn: TBitBtn;
procedure CycleBtnClick(Sender: TObject);
procedure ExtendBtnClick(Sender: TObject);
procedure AbortBtnClick(Sender: TObject);
public
Labels : array[1..NumStatusLines] of TLabel;
OnLabel : Cardinal;
Dialer : TApdCustomModemDialer;
SaveTrig : TTriggerTimerEvent;
DialTrig : Integer;
constructor Create(AOwner : TComponent); override;
procedure AddStatusString(const St : String);
{-Put a status string in the display}
procedure AddResString(const ResID : Cardinal);
{-Load a status string from a resource and display it}
procedure DoDial(const ADialer : TApdCustomModemDialer);
{-Begin dialing}
{dialer event handlers}
procedure FrmRetryStart(Sender : TObject);
procedure FrmRetryCount(M : TObject; Remaining : Word);
procedure FrmRetryEnd(Sender : TObject);
procedure FrmDialStart(Sender : TObject);
procedure FrmConnect(Sender : TObject);
procedure FrmDialCount(M : TObject; Remaining : Word);
procedure FrmGotLineSpeed(M : TObject; Speed : LongInt);
procedure FrmBusy(Sender : TObject);
procedure FrmVoice(Sender : TObject);
procedure FrmError(Sender : TObject);
procedure FrmNoCarrier(Sender : TObject);
procedure FrmNoDialTone(Sender : TObject);
procedure FrmDialTimedOut(Sender : TObject);
procedure FrmTooManyTries(Sender : TObject);
procedure FrmConnectionEstablished(Sender : TObject);
procedure FrmTriggerTimer(CP : TObject; TriggerHandle : Word);
end;
{.Z-}
TApdDialerDialog = class(TCommonDialog)
protected {private}
{.Z+}
FModem : TApdCustomModem;
FPhoneNumber : String;
FMaxDialTries : Integer;
FRetrySecs : Integer;
FDialerOptions : TDialerOptions;
FCaption : TCaption;
procedure Notification(AComponent : TComponent; Operation : TOperation); override;
function GetVersion : string;
procedure SetVersion(const Value : string);
public
constructor Create(AOwner : TComponent); override;
{.Z-}
function Execute : Boolean; {$IFDEF VERSION3} override; {$ENDIF}
published
property Version : string
read GetVersion
write SetVersion
stored False;
{dialing data}
property Modem : TApdCustomModem
read FModem write FModem;
property PhoneNumber : String
read FPhoneNumber write FPhoneNumber;
property MaxDialTries : Integer
read FMaxDialTries write FMaxDialTries default addDefMaxDialTries;
property RetrySecs : Integer
read FRetrySecs write FRetrySecs default addDefRetrySecs;
property DialerOptions : TDialerOptions
read FDialerOptions write FDialerOptions;
property Caption : TCaption
read FCaption write FCaption;
end;
implementation
{$R *.DFM}
{TApdCustomModemDialer}
procedure TApdCustomModemDialer.Notification(AComponent : TComponent; Operation : TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) then begin
{see if our modem is going away}
if (AComponent = FModem) then begin
FModem := nil;
ComPort := nil;
end;
end else if (Operation = opInsert) then begin
{check for modem being installed}
if not Assigned(FModem) and (AComponent is TApdCustomModem) then
Modem := TApdCustomModem(AComponent);
end;
end;
procedure TApdCustomModemDialer.PrepareDialing;
{-Start a timer to trigger the beginning of a dial attempt}
begin
DialIdx := ComPort.AddTimerTrigger;
ComPort.SetTimerTrigger(DialIdx, 4, True);
end;
procedure TApdCustomModemDialer.RetryDial;
{-Retry the last dial attempt, if possible}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -