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

custom print dialog

edited February 2003 in End User
Hello All

Delphi 5, RB 6.03, ExtraDevices

We are trying to configure the print dialog ( or register a custom version )
from within an end user reporting
solution. I was hoping to use a pass through so that from RAP I could get
Delphi to register the custom dialog. I can't get it to work no matter which
events I use. And where do I unregister it again.

On the standard dialog, we would like to be able to check the 'Print to
file' option and
set the file type to Excel for reports that are only intended for output to
Excel.

Alternatively, we could use a custom dialog that is basically a save dialog
to save to Excel or PDF accordingly.

Is this possible ?

Thanks Nard for your reply to my previous posting but that didn't work.

Regards, Paul Hughes.

Comments

  • edited February 2003
    Nard's approach in his reply works for me. First thing to do is to get the
    end user demo to work as he has described. Perform a copy/paste of those
    three property assignments and use them in your application. Those changes
    force the print dialog to check the PrintToFile option and have the chosen
    device selected. From RAP, it doesn't work in the OnPrintDialogCreate
    event? Can you verify that you RAP pass through function is working
    correctly?

    First, get the approach to work using Delphi event handlers and not RAP.
    Once you get it working, then port it to work in RAP.

    You can register the form class anytime before the OnPrintDialogCreate
    event. Use the report's BeforePrint event or the global OnCreate event. Then
    unregister it in the AfterPrint or OnDestroy global event. That should work
    because the print dialog is created just before the OnPrintDialogCreate
    event is triggered by the producer.

    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited February 2003
    Thanks Jim

    I have decided on the simpler option of controlling the standard dialog.
    This means setting the PrintToFile checkbox and choosing a file format.

    I have a the following procedure which looks at the ReportFileType variable
    which is set from a RAP function.

    procedure TMainForm.PrintDialogCreateEvent(Sender: TObject);
    begin
    if ReportFileType <> '' then begin { this is set by a RAP pass through
    procedure }
    ppReport1.PrintDialog.AllowPrintToFile := True;
    ppReport1.PrintDialog.DeviceType := ReportFileType;
    end;
    end;

    This works OK in Delphi but I can't find a suitable place to make the RAP
    call when trying to print the report directly from the Print button without
    a preview.

    GlobalOnCreate
    Preview then Print OK
    Print directly Dialog is unchanged as event fires after
    standard print dialog is Closed [OK'd]

    Report.OnPrintDialogCreate(RAP)
    Preview then Print OK
    Print directly Event fires before dialog is displayed but the
    dialog has not been altered as required.

    Report.BeforePrint(RAP)
    Preview then Print OK
    Print directly Dialog is unchanged as event fires after
    standard print dialog is Closed [OK'd]

    Any suggstions please Jim ?
    Regards Paul.

  • edited February 2003
    The RAP event handler for the PrintDialogCreate is what you want to use.
    However, you are trying to use the Delphi event handler to set this. It
    doesn't work because you are setting the RAP REportFileType in the events
    which fire after the Delphi event. So, to correct this, you need to make a
    new pass through function call in the RAP OnPrintDialogCreate event so that
    it modifies the print dialog object at that time. This is the only way it
    will work. The other events fire when the report is actually generating, so
    the global OnCreate happens to fire after the OnPrintDialogCreate in RAP in
    this case, when normally it is the first event to fire.


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited February 2003
    Thanks Jim

    That works a treat now, cheers !!

    Paul.

This discussion has been closed.