📄 adfax.pas
字号:
{$ENDIF}
nil); {parameter}
if MsgHandler = 0 then
raise EInternal.Create(ecInternal, False);
ShowWindow(MsgHandler, sw_Hide);
{Add to global list}
Node := nil;
try
New(Node);
Node^.fwWindow := MsgHandler;
Node^.fwFax := Self;
FaxList.Add(Node);
except
on EOutOfMemory do begin
if Node <> nil then
Dispose(Node);
raise;
end;
end;
end;
procedure TApdCustomAbstractFax.Notification(AComponent : TComponent;
Operation : TOperation);
{-Handle dependent components coming and going}
begin
inherited Notification(AComponent, Operation);
if Operation = opRemove then begin
{Owned components going away}
if AComponent = FComPort then
ComPort := nil;
if AComponent = FStatusDisplay then
StatusDisplay := nil;
if AComponent = FFaxLog then
FaxLog := nil;
end else if Operation = opInsert then begin
{Check for new comport}
if AComponent is TApdCustomComPort then begin
if not Assigned(FComPort) then
ComPort := TApdCustomComPort(AComponent);
end;
{Check for new status component}
if AComponent is TApdAbstractFaxStatus then begin
if not Assigned(FStatusDisplay) then
if not Assigned(TApdAbstractFaxStatus(AComponent).FFax) then
StatusDisplay := TApdAbstractFaxStatus(AComponent);
end;
{Check for new status component}
if AComponent is TApdFaxLog then begin
if not Assigned(FFaxLog) then
if not Assigned(TApdFaxLog(AComponent).FFax) then
FaxLog := TApdFaxLog(AComponent);
end;
end;
end;
procedure TApdCustomAbstractFax.Loaded;
begin
inherited Loaded;
{reset status interval if old version}
if (FVersion = 0) then begin
Fax^.aPData^.aStatusInterval := 1;
FVersion := 1;
end;
end;
procedure TApdCustomAbstractFax.PrepareTapi;
{ prepare the TapiDevice }
begin
if FTapiPrepared then Exit; {!!.04}
FWaitForTapi := False;
Fax^.aPData^.aUsingTapi := True; {!!.04}
FUserOnTapiPortOpen := FTapiDevice.OnTapiPortOpen;
FTapiDevice.OnTapiPortOpen := FaxTapiPortOpenClose;
FUserOnTapiPortClose := FTapiDevice.OnTapiPortClose;
FTapiDevice.OnTapiPortClose := FaxTapiPortOpenClose;
FUserOnTapiStatus := FTapiDevice.OnTapiStatus;
FTapiPrepared := True; {!!.04}
end;
procedure TApdCustomAbstractFax.UnprepareTapi;
{ called from apwFaxFinish, restore the original event handlers }
begin
Fax^.aPData^.aUsingTapi := False; {!!.04}
FTapiDevice.OnTapiPortOpen := FUserOnTapiPortOpen;
FTapiDevice.OnTapiPortClose := FUserOnTapiPortClose;
FTapiPrepared := False; {!!.04}
end;
procedure TApdCustomAbstractFax.OpenTapiPort;
{ perform a ConfigAndOpen synchronously }
begin
{ assumes that TapiDevice is assigned }
FWaitForTapi := True;
{ open with TAPI }
FTapiDevice.ConfigAndOpen;
{ wait for the OnTapiPortOpen }
WaitForTapi; {!!.04}
{while FWaitForTapi do} {!!.04}
{DelayTicks(2, True);} {!!.04}
end;
procedure TApdCustomAbstractFax.CloseTapiPort;
{ perform a CancelCall synchronously }
begin
if FTapiDevice.WaitingForCall then Exit; {!!.04}
FWaitForTapi := True;
{ tell TAPI to close the port }
FTapiDevice.CancelCall;
{ wait for the OnTapiPortClose }
WaitForTapi; {!!.04}
{while FWaitForTapi do} {!!.04}
{DelayTicks(2, True);} {!!.04}
end;
procedure TApdCustomAbstractFax.FaxTapiPortOpenClose(Sender : TObject);
begin
if FComPort.Open then begin
// it's an OnTapiPortOpen
if Assigned(FUserOnTapiPortOpen) then
FUserOnTapiPortOpen(Sender);
end else begin
// it's an OnTapiPortClose
if Assigned(FUserOnTapiPortClose) then
FUserOnTapiPortClose(Sender);
end;
FWaitForTapi := False;
end;
const
CurComponentVersion = 1;
procedure TApdCustomAbstractFax.ReadVersionCheck(Reader : TReader);
begin
FVersion := Reader.ReadInteger;
end;
procedure TApdCustomAbstractFax.WriteVersionCheck(Writer : TWriter);
begin
FVersion := CurComponentVersion;
Writer.WriteInteger(FVersion);
end;
procedure TApdCustomAbstractFax.DefineProperties(Filer : TFiler);
begin
inherited DefineProperties(Filer);
Filer.DefineProperty('FakeProperty', ReadVersionCheck, WriteVersionCheck, True);
end;
{TApdCustomReceiveFax}
constructor TApdCustomReceiveFax.Create(AOwner : TComponent);
{-Create a TApdReceiveFax component}
begin
inherited Create(AOwner);
{Create the message handler window instance}
if not (csDesigning in ComponentState) then begin
RegisterFaxMessageHandlerClass;
CreateFaxMessageHandler;
end;
{Create the ReceiveFax data structure}
CheckException(Self,
fInitC12ReceiveFax(Fax, '', nil, MsgHandler));
{Inits}
FaxMode := fmReceive;
PrepProc := fPrepareFaxReceive;
FaxFunc := fFaxReceive;
{All property inits (abstract and receive)}
AbortNoConnect := adfDefAbortNoConnect;
ExitOnError := adfDefExitOnError;
SoftwareFlow := adfDefSoftwareFlow;
InitBaud := adfDefInitBaud;
NormalBaud := adfDefNormalBaud;
FaxClass := adfDefFaxClass;
AnswerOnRing := adfDefAnswerOnRing;
FaxAndData := adfDefFaxAndData;
OneFax := adfDefOneFax;
ConstantStatus := adfDefConstantStatus;
FaxNameMode := adfDefFaxNameMode;
DestinationDir := adfDefDestinationDir;
FaxFileExt := adfDefFaxFileExt;
end;
destructor TApdCustomReceiveFax.Destroy;
{-Destroy a TApdReceiveFax component}
begin
fDoneC12ReceiveFax(Fax);
inherited Destroy;
end;
function TApdCustomReceiveFax.GetAnswerOnRing : Word;
{-Return the number of rings to wait before answering}
begin
Result := PC12FaxData(Fax)^.fCData^.cAnswerOnRing
end;
procedure TApdCustomReceiveFax.SetAnswerOnRing(const NewVal : Word);
{-Set the number of rings to count before answering}
begin
PC12FaxData(Fax)^.fCData^.cAnswerOnRing := NewVal;
end;
function TApdCustomReceiveFax.GetFaxAndData : Boolean;
{-Return the FaxAndData setting}
begin
Result := (PC12FaxData(Fax)^.fCData^.cFaxAndData = '1')
end;
procedure TApdCustomReceiveFax.SetFaxAndData(const NewVal : Boolean);
{-Enable/disable adaptive answer}
const
FaxData : array[Boolean] of Char = ('0', '1');
begin
PC12FaxData(Fax)^.fCData^.cFaxAndData := FaxData[NewVal];
end;
function TApdCustomReceiveFax.GetOneFax : Boolean;
{-Return the value of the OneFax option}
begin
Result := PC12ReceiveFax(Fax)^.fOneFax
end;
procedure TApdCustomReceiveFax.SetOneFax(NewValue : Boolean);
{-Set the OneFax option}
begin
PC12ReceiveFax(Fax)^.fOneFax := NewValue;
end;
function TApdCustomReceiveFax.GetConstantStatus : Boolean;
{-Return the value of the ConstantStatus option}
begin
Result := PC12ReceiveFax(Fax)^.fConstantStatus
end;
procedure TApdCustomReceiveFax.SetConstantStatus(const NewValue : Boolean);
{-Set ConstantStatus behavior on/off}
begin
PC12ReceiveFax(Fax)^.fConstantStatus := NewValue;
end;
function TApdCustomReceiveFax.GetDestinationDir : TPassString;
{-Return the destination directory}
begin
Result := Fax^.aPData^.aDestDir
end;
procedure TApdCustomReceiveFax.SetDestinationDir(const NewDir : TPassString);
{-Set the destination directory}
begin
Fax^.aPData^.aDestDir := AddBackSlash(NewDir);
end;
procedure TApdCustomReceiveFax.apwFaxAccept(CP : TObject; var Accept : Boolean);
{-Process the fax accept message}
begin
if Assigned(FOnFaxAccept) then
FOnFaxAccept(CP, Accept)
else
Accept := True;
end;
procedure TApdCustomReceiveFax.apwFaxName(CP : TObject;
var Name : TPassString);
{-Process the fax name message}
begin
if Assigned(FOnFaxName) then
{Use users faxname hook}
FOnFaxName(CP, Name)
else begin
{Nothing assigned, use one of the built in methods}
case FFaxNameMode of
fnMonthDay :
Name := afFaxNameMD(Fax);
fnCount :
Name := afFaxNameCount(Fax);
else
if FFaxFile = '' then {!!.01}
Name := 'noname.apf'
else {!!.01}
Name := FFaxFile; {!!.01}
end;
end;
FFaxFile := Name; {!!.01}
end;
procedure TApdCustomReceiveFax.PrepareTapi;
begin
inherited;
FTapiDevice.OnTapiStatus := FaxTapiStatus;
end;
procedure TApdCustomReceiveFax.UnprepareTapi;
begin
inherited;
FTapiDevice.OnTapiStatus := FUserOnTapiStatus;
end;
procedure TApdCustomReceiveFax.TapiPassiveAnswer;
{ set up the TAPI device for AutoAnswer }
begin
FTapiDevice.AnswerOnRing := AnswerOnRing + 10;
FTapiDevice.AutoAnswer;
end;
procedure TApdCustomReceiveFax.FaxTapiStatus(CP: TObject; First, Last: Boolean;
Device, Message, Param1, Param2, Param3: LongInt);
begin
if Assigned(FUserOnTapiStatus) then
FUserOnTapiStatus(CP, First, Last, Device, Message, Param1, Param2, Param3);
if (Message = Line_LineDevState) and (Param1 = LineDevState_Ringing) then begin
if Param3 >= AnswerOnRing - 1 then begin
FTapiDevice.CancelCall;
OpenTapiPort;
WaitForTapi; {!!.04}
{while not FComPort.Open do} {!!.04}
{DelayTicks(2, True);} {!!.04}
{Make sure comport is open, pass handle to fax}
CheckPort;
{Validate the port that TAPI gave us}
with FComPort do begin {!!.04}
Databits := 8; {!!.04}
Stopbits := 1; {!!.04}
Parity := pNone; {!!.04}
Baud := 19200; {!!.04}
InSize := 8192; {!!.04}
OutSize := 8192; {!!.04}
HWFlowOptions := [hwfUseRTS, hwfRequireCTS]; {!!.04}
end; {!!.04}
{Start the fax}
{StartManualReceive(True);} {!!.04}
{if not PC12ReceiveFax(Fax)^.FcData^.cInitSent then} {!!.04}
{PC12ReceiveFax(Fax)^.fFirstState := rfInit;} {!!.04}
afStartFax(Fax, fPrepareFaxReceive, fFaxReceive);
end;
end;
end;
procedure TApdCustomReceiveFax.InitModemForFaxReceive;
{-Send nessessary commands to initialize modem for fax receive}
begin
if not Fax^.aPData^.aInProgress then begin
CheckPort;
if not fInitModemForFaxReceive(Fax) then
CheckException(Self, ecFaxInitError);
end;
end;
procedure TApdCustomReceiveFax.PrepareConnectInProgress;
{-Prepare to connect to a fax session already in progress}
begin
fSetConnectState(Fax);
end;
procedure TApdCustomReceiveFax.StartReceive;
{-Start a background fax receive session}
begin
with Fax^ do begin
{ integrate with TAPI }
if Assigned(FTapiDevice) then begin
{ set up the event handlers }
PrepareTapi;
{ put TapiDevice in AutoAnswer mode }
TapiPassiveAnswer;
{ don't need to do anything else here, we'll react to TAPI status }
Exit;
end;
{Make sure comport is open, pass handle to fax}
CheckPort;
{Start the fax}
if FaxMode = fmReceive then begin
if not PC12ReceiveFax(Fax)^.FcData^.cInitSent then
PC12ReceiveFax(Fax)^.fFirstState := rfInit;
afStartFax(Fax, fPrepareFaxReceive, fFaxReceive);
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -