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

ReportDesigner

edited February 2002 in General

We wrote our own custom events to print reports on Dot Matrix printers.

When the form previewer is presented, we want to call our own print
method when the printer icon is clicked.


How can we accomplish this ???


Thank you.


Neil Huhta

Comments

  • edited February 2002
    Create a custom previewer. Descend from TppPreview and override this method
    to call you own print routine.

    procedure PerformPreviewAction(aPreviewAction: TppPreviewActionType);

    Register you new preview class and you're good to go.


    ...


    {@TppMyPreview}

    TppMyPreview = class(TppPreview)
    private
    procedure MyPrint;

    public
    procedure PerformPreviewAction(aPreviewAction: TppPreviewActionType);
    override;

    end; {class, TppMyPreview}

    implementation

    uses
    ppTypes;

    procedure TppMyPreview.MyPrint;
    begin
    {do your printing code}
    beep;
    end;

    procedure TppMyPreview.PerformPreviewAction(aPreviewAction:
    TppPreviewActionType);
    begin

    if (aPreviewAction = paPrint) then
    MyPrint

    else
    inherited PerformPreviewAction(aPreviewAction);

    end; {procedure, PerformPreviewAction}


    {***************************************************************************
    ***
    *
    ** I N I T I A L I Z A T I O N / F I N A L I Z A T I O N
    *
    {***************************************************************************
    ***}



    initialization
    TppPreviewPlugin.UnRegister(TppPreview);
    TppPreviewPlugIn.Register(TppMyPreview);

    finalization
    TppPreviewPlugIn.UnRegister(TppMyPreview);
    TppPreviewPlugIn.Register(TppPreview);




    Cheers,

    Jim Bennett
    Digital Metaphors

  • edited February 2002
    Jim:

    Thanks - that makes sense. How does my ppReport component know to use
    the descendent previewer ???

    Neil Huhta
  • edited February 2002
    The magical replacement of the previewer is handled in the registration
    calls in the initializatoin/finalization section:)

    Cheers,

    Jim Bennett
    Digital Metaphors

  • edited February 2002
    Jim:

    Is there a way to use the custom previewer ONLY in certain areas of my
    program ( for instance in the Reports.Pas unit and the InvReports.Pas unit
    only ) ???



    Neil
  • edited February 2002
    The registration mechanism is called in the intialization finalization
    sections of a unit, but you can call these methods anytime you want. Before
    you call the Report.Print in one of your pas files, you can unregister the
    current previewer, then register a new previewer, call print, then
    unregister the new previewer and reregister the old previewer.

    Instead of registering the previewer in the intialization/finalization
    section, do it only in the few cases where you need a special previewer:

    ..
    TppPreviewPlugin.UnRegister(TppPreview);
    TppPreviewPlugIn.Register(TppMyPreview);

    ppReport1.Print;

    TppPreviewPlugIn.UnRegister(TppMyPreview);
    TppPreviewPlugIn.Register(TppPreview);
    ..

    Cheers,

    Jim Bennett
    Digital Metaphors

This discussion has been closed.