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

Stop Printing

edited October 2001 in General
How do I keep someone from actually printing what is in the previewer. My
attempt at doing such is to disable printing to paper capabilities when my
program is functioning in demo mode. I have tried the OnPrintDialogClose
event, but this doesn't do anything when the user presses the Print button
in the top left corner of the previewer. Or am I just doing something
wrong.

Jeff Kreider

Comments

  • edited October 2001
    You could create your own previewer which doesn't have the print button on
    it. The previewer is replaceable. See ppPreview.pas in ..\RBuilder\Source
    for an example of creating a TppCustomPreview descendent. Don't forget to
    register this new previewer in the initialization section.


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited October 2001
    Jim,
    Three things:
    1) Is there a simple example somewhere on creating a previewer. I haven't
    had to do what you said that I need to do.
    2) I found what was looking for in dm0124.pas. I believe there is a type-o
    on line 193. It says,
    ppTextToPageList('1,30', Report.PrinterDevice.PageList, True);
    but I believe it should read,
    ppTextToPageList('1,30', ppReport.PrinterDevice.PageList, True);
    3) The other problem I got was an EAccessViolation at runtime when the
    following line is executed in my program,
    ppReport1.PrinterDevice.PageSetting := psPageList;
    I took the copied and pasted the BeforePrint event code from dm0124.pas and
    put it into my BeforePrint event. Any ideas as to why this would occur?

    Thanks for your help.

  • edited November 2001
    1. The TppPreview class shows how to create a new previewer, with all of the
    controls and such. By registering your TppCustomPreview class, it will get
    created for you by RB. All you have to do is create a copy of the
    TppPreview class in your project, and rename it. Then make an unregister
    call to unregister the current preview, and register your new preview class,
    as shown at the bottom of the ppPreview.pas file in our source.

    2. Yep, that's a typo, however, it works the same. Thanks for pointing it
    out.

    3. As far as the AV, you'll need to check for nil as the code in the demo
    does:

    {note: PrinterDevice will be nil if NOT printing to printer }
    if (Report.PrinterDevice <> nil) then
    begin
    Report.PrinterDevice.PageSetting := psPageList;

    {note: this is a useful routine for converting the page list text
    to the list of strings}

    {print pages 1 and 30 }
    ppTextToPageList('1,30', Report.PrinterDevice.PageList, True);
    end;



    Cheers,

    Jim Bennett
    Digital Metaphors


This discussion has been closed.