1

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 Answers1

1

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.

Ken White
  • 123,280
  • 14
  • 225
  • 444
  • Thank you for the documentation link. I have read it and the way I understand it I have tried to add FaxServer.ListenToServerEvents(fsetOUT_QUEUE) to the code and created a procedure FaxServer_OnOutgoingJobChanged(FaxServer: IFaxServer; JobId: String; JobStatus: FaxJobStatus) that just returns a message. Now, how do I make this procedure handle the IFaxServerNotify.OnOutgoingJobChanged method? – user3759071 Jul 07 '14 at 03:28
  • It's much more complicated than that, I'm afraid. You need to implement a class to use as a COM Event Sink, and then register for the event using Advise() (and unregister when you're finished using Unadvice, IIRC). Remy Lebeau just demonstrated doing so here (not for a FAXStatus, though). I'll see if I can find a link to that answer. – Ken White Jul 07 '14 at 12:39
  • Here's a [link to the answer](http://stackoverflow.com/a/24558046) I mentioned by Remy. – Ken White Jul 07 '14 at 12:43
  • Thanks again for that insight. I found an [even sink documentation](http://www.gekko-software.nl/Delphi/art10.htm). Now the problem is, the faxcomexlib is in faxcomexlib_tlb.pas and not faxcomexlib.tlb. As I understand it, .tlb can be open in the type library. Is there a way to convert .pas into .tlb? or is this question subject to another question post? – user3759071 Jul 09 '14 at 01:38
  • You don't "convert a .pas into a .tlb". You add that `faxcomexlib_tlb.pas` file to your uses clause (just like you would any other Delphi unit), and then you can use the interfaces and classes declared in it within your own code. – Ken White Jul 09 '14 at 02:14
  • I just figured out the problem. I have been using the IFaxServer instead of the TFaxServer component. Thank you for everything. If not for your answers, I wouldn't have understood automation. – user3759071 Jul 11 '14 at 03:30
  • I was able to invoke the event FOnOutgoingJobChanged(Self, Params[2] {const IFaxJobStatus}, Params[1] {const WideString}, Params[0] {const IFaxServer}) from the FAXCOMEXLIB but then the event procedure from the component of the client side has this variable parameter pJobStatus: OleVariant. Thinking that directly coding pJobStatus.Status would get me the status but then an error occurred stating that method is not under the automation. How do I get the value of this variable? – user3759071 Jul 11 '14 at 09:26