Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

After Print Event Does Not Fire

edited February 2005 in General
All

In the newsgroup I can find discussion about the After Print not firing
because the report has been loaded from a template (which is exactly my
case).
I am afraid what I do not seem to be able to comprehend is how to repair the
links.

One discussion talks about creating Pass Through functions and references
example 031 to 033 in the examples which inturn has new type and shows
examples of Get Signature and other complexities I do not understand.

There is also a Tech Tip : Using Template Events which includes

procedure TForm1.myTemplateOnLoadEndEvent(Sender: TObject);
begin

{add code here to initial the report or data, etc. }
ppReport1.PrinterSetup.MarginTop := 0.5;

end;

so I set up the following

Template.New;
Template.FileName := OpenCal.RptDirectory +
'\ADSporder.rtm';
Template.LoadFromFile;
Template.OnLoadEnd := myTemplateOnLoadEndEvent;

+ the following

procedure TwinPurchase.myTemplateOnLoadEndEvent(Sender:
TObject);
begin
MainDataModule.ppReport1.AfterPrint :=
MainDataModule.ppReport1AfterPrint;
end;

The myTemplateOnLoadEndEvent(Sender: TObject); occurs OK but still the
AfterPrint event still does not fire.

Could someone please explain in simplistic terms how to overcome this
annoyance.

Many thanks in advance.

Philip L Jackson

Comments

  • edited February 2005
    Hi Philip,

    It looks like the message you found was addressing a customer that was using
    RAP. Pass Thru functions are specific to RAP which is our internal
    reporting language that enables you to keep all report code local to the
    template file.

    Looking at your code below, it looks like you are assigning the OnLoadEnd
    event after you are calling LoadFromFile. You will need to assign this
    event before loading the template in order for it to fire at the time you
    desire.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited March 2005
    Hi Nico

    Thanks - what a difference the position of one line makes, though it has
    exposed another problem.

    The report is OK and after printing the "After Print" code now executes,
    this then runs the following code, however
    when the PrintToDevices is called, the report is again sent to the printer
    so I get 2 copies. How do I stop this 2nd print from occuring?

    One other question - any ideas why does the code lPDFDevice.Free;
    below cause an access violation?

    Thanks in advance

    Philip L Jackson


    MainDataModule.ppReport1.ShowPrintDialog := FALSE;
    MainDataModule.ppReport1.AllowPrintToFile := TRUE;
    MainDataModule.ppReport1.DeviceType := dtPDF;

    try
    if FileExists(MainDataModule.ppReport1.TextFileName) then
    SysUtils.DeleteFile(MainDataModule.ppReport1.TextFileName);
    lPDFDevice := TppPDFDevice.Create(nil);

    if (FOutputStream = nil) then
    FOutputStream := TMemoryStream.Create
    else FOutputStream.Clear;

    lPDFDevice.PDFSettings :=
    MainDataModule.ppReport1.PDFSettings;
    lPDFDevice.OutputStream := FOutputStream; //
    assign output stream
    lPDFDevice.Publisher :=
    MainDataModule.ppReport1.Publisher;
    MainDataModule.ppReport1.AfterPrint := nil;
    MainDataModule.ppReport1.PrintToDevices;
    FOutputStream.SaveToFile(MainDataModule.ppReport1.TextFileName);
    finally
    // lPDFDevice.Free;
    end;







  • edited March 2005
    Hi Philip,

    Now I see what you are trying to do :).

    I would recommend taking a different approach to the task of printing to
    multiple devices at once. This would involve creating two separate
    TppDevices (i.e. Printer Device, and PDF Device), assigning their publishers
    and then calling PrintToDevices only once. The reason you are getting two
    copies is that when you call PrintToDevices, it is printing to every device
    connected to the publisher. This may be what is causing the AV as well.

    I made a small test app to try to recreate the AV you are getting but have
    been unsuccessfull. Below is the code I used. If you are still getting the
    AV once you change your app around, please send an example to
    support@digital-metaphors.com and I'll take a look at it for you.

    var
    lPDFDevice: TppPDFDevice;
    begin

    lPDFDevice := TppPDFDevice.Create(Self);

    try
    lPDFDevice.OutputStream := FFileStream;

    lPDFDevice.PDFSettings := ppReport1.PDFSettings;

    lPDFDevice.Publisher := ppReport1.Publisher;

    ppReport1.PrintToDevices;

    finally
    lPDFDevice.Free;
    end;

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.