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

Changing a report line depending on where the report is printed to.

edited January 2004 in General
Hello,

I have a report in which I would like to display 1 line if the report is
being displayed to the screen else display a different line of text.

I thought this would work.

In the
OnCalcFields event of my TQuery I decode the value in the database and
decide what the report should show as far as text. So I put in the
following text:

if (ppReport.DeviceType = 'Screen') then
Text := 'Hello'
else
Text := 'Good by';

That seems to work but no I have a button on my preview form that allows the
user to quickly print the current page to the default printer.

procedure TppMyPrintPreview.btnPrintCurrentPageClick(Sender: TObject);
var
lPrinterDevice: TppPrinterDevice;
lPage: TppPage;

begin

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

end;

The onCalcFields event does not get called this way so I never get a chance
to change the line of text. Is there a way I can accomplish this?

Also I have found that if the user clicks the Print Current Page button more
than once for the same preview all clicks after the first one will create an
exception, Am I doing something wrong in the printing of the current page?

Thanks in advance,
Rodger Van Kirk

Comments

  • edited January 2004
    Hi Rodger,

    Be sure you do not have Report.CachePages set to true. This would be the
    only reason I can think of that your OnCalcFields event would not fire for
    your query. You can also use the Report.BeforePrint to set these values and
    be sure that it gets fired for every report execution.

    --
    Best Regards,

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