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

Customizing the Print Preview

edited April 2009 in General
Long time ago I created a new print preview window based on an example from
someplace where you copy ppPrvDlg rename it and set the registration. Well
I decided to update it to the more recent looking window. I have completed
this part just fine. I also found an example where I can add buttons to the
top toolbar but this has brung up a couple of questions.

1) How do I customize where the new button gets placed? By calling
ToolBar.AddButton() it just adds it to the beginning. I want the button to
appear just before the close button with some separators around it?

2) In my previous print preview I had a button for printing the current page
to the default printer. I took a stab at it from my old version. Is this
the best way to accomplish this?

var
lPrinterDevice: TppPrinterDevice;
lPage: TppPage;

begin

// print current page
lPage := Viewer.CurrentPage;
lPrinterDevice := TppPrinterDevice.Create(nil);
try
lPrinterDevice.Printer.PrinterSetup.PrinterName :=
Viewer.Report.Printer.PrinterName;
lPrinterDevice.StartJob;
lPrinterDevice.PageRequest.PageRequested := lPage.AbsolutePageNo;
lPrinterDevice.PageRequest.PageSetting := psSinglePage;
lPrinterDevice.ReceivePage(lPage);
lPrinterDevice.EndJob;
finally
lPrinterDevice.Free;
end;


Thanks in advance,
Rodger Van Kirk

Comments

  • edited April 2009
    Hi Rodger,

    1. In order to add a button in the middle of the other preview toolbar
    buttons, you will need to completely recreate the entire toolbar. Take a
    look at the CreateToolBarItems routine for how it is currently created. You
    will basically copy this code and add your own button where you need it.

    2. Looks great :). Also you could try something similar only using the
    printer device created when Report.Print is called from the BeforePrint
    event...

    procedure TForm1.ppReport1BeforePrint(Sender: TObject);
    begin
    if ppReport1.PrinterDevice <> nil then
    begin
    ppReport1.PrinterDevice.PageRequest.PageSetting := psSinglePage;
    ppReport1.PrinterDevice.PageRequested := ppReport1.CurrentPage;
    end;

    end;


    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited April 2009
    Nico,

    I'm working on writing my own CreateToolBarItems routine.

    I have the code in the on click event of a button so the user can quickly
    print the current page and it appears to run correctly but for some reason
    nothing gets sent to the printer.

    Rodger


  • edited April 2009
    Nico,

    I think I'm missing something here. I copied the CreateToolBarItems code
    added the Private objects for the buttons and everything compiles. When I
    try to run it I get an Access Violation in the following code:

    { TppPrintPreview.Init }

    procedure TppMyPrintPreview.Init;
    begin

    if (Report is TppProducer) then
    FPreview.Viewer.Report := TppProducer(Report);

    FPreview.BeforePreview; <------- AV

    end;

    I'm sure its something obvious and I'm just not seeing it. Only happens
    when I create my own buttons. If I remove the creation of the "default"
    buttons and only put mine in where it is added at the beginning of the
    buttons everything works. But if I try to manually create them all then it
    crashes.

    Any ideas?

    Thanks in advance,
    Rodger Van Kirk

  • edited April 2009
    Fixed this issue. Appears there was something going on with my computer. I
    couldn't get anything to print. Restarted and it worked.

    Rodger Van Kirk


  • edited April 2009
    Hi Rodger

    If you trace into the BeforePreview routine, where does the AV occur in the
    RBuilder code? Is the Report perhaps nil?
    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited April 2009
    Won't let me step into it.

    Regards,
    Rodger van Kirk

  • edited April 2009
    Should have clarified a bit.

    If I add the source directory to the library I get compile errors like:
    [DCC Error] Main.pas(97): F2051 Unit raParser was compiled with a different
    version of ppRTTI.TraRTTIClassRegistry

    Regards,
    Rodger Van Kirk


  • edited April 2009
    Hi Rodger,

    If you would like, you can try sending me the preview plugin you are
    creating and I can take a look at it for you. Send it in .zip format to
    support@digital-metaphors.com.

    --
    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.