Get Fax Job Status

426 views Asked by At

I have tried the code below for sending fax:

uses
  ComObj, ActiveX, FAXCOMEXLib_TLB;

procedure TForm1.Button1Click(Sender: TObject);
var
  I: Integer;
  JobIDs: OleVariant;
  FaxServer: IFaxServer2;
  FaxDocument: IFaxDocument2;
begin
  try
    FaxServer := CoFaxServer.Create;
    FaxServer.Connect('');
    FaxDocument := CoFaxDocument.Create;
    FaxDocument.Body := 'd:\Document.pdf';
    FaxDocument.DocumentName := 'Document name';
    FaxDocument.Recipients.Add('+1 (425) 555-4567', 'Bill');
    FaxDocument.Sender.Name := 'Bob';
    FaxDocument.Sender.BillingCode := '23A54';
    FaxDocument.Sender.Department := 'Accts Payable';
    FaxDocument.Sender.FaxNumber := '+972 (4) 555-9070';
    JobIDs := FaxDocument.ConnectedSubmit(FaxServer);

    for I := VarArrayLowBound(JobIDs, 1) to VarArrayHighBound(JobIDs, 1) do
      ShowMessage('Job ID: ' + VarArrayGet(JobIDs, [I]));
  except
    on E: EOleSysError do
      ShowMessage(
        Format('Sending of the fax failed! %s [%d]', [E.Message, E.ErrorCode])
      );
  end;
end;

What I was trying to do was get the job status for the fax sent. I have tried to add

var
  FaxJobStatus: IFaxJobStatus;
.....

FaxJobStatus := CoFaxJobStatus.Create;

compiled the source code and found no error but after executing the code, it fails at FaxJobStatus := CoFaxJobStatus.Create saying "class not registered".

1

There are 1 answers

7
Ken White On BEST ANSWER

From the IFaxJobStatus documentation:

You do not create the FaxJobStatus object. It is received as part of a notification when you implement IFaxServerNotify::OnIncomingJobChanged or IFaxServerNotify::OnOutgoingJobChanged, which include a parameter of the type FaxJobStatus. When the event occurs and the implemented function is called, you receive this object containing the dynamic information.

So you have to register for the IFaxServerNotify.OnIncomingJobChanged or IFaxServerNotify.OnOutgoingJobChanged events. When the event is received, you get the FaxJobStatus object and can read its Status property.