Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
751 views
in Technique[技术] by (71.8m points)

delphi - How to show the PrintDialog just after showing the preview in FastReport?

I'm using Delphi to develop a desktop database application, and I've an invoice report made with FastReport, I know that I can use InvoiceReport.ShowReport to show it's preview. So I need to know how I can show the print dialog automatically just after showing the preview. The user then can print it or cancel the dialog


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To show print dialog in Fast Report you simply call Print with PrintOptions.ShowDialog:=True. By default the preview form is shown modal, so the easiest solution is to change it and call Print:

InvoiceReport.PreviewOptions.Modal:=False;
InvoiceReport.PrintOptions.ShowDialog:=True;
InvoiceReport.ShowReport;
InvoiceReport.Print;

If you need to keep the preview form modal, the other option is to handle OnPreview event and call Print, but you have to postpone the procedure, so for example:

const 
  UM_PRINT_DIALOG = WM_USER+1;

...

procedure ShowPrintDialog(var Message: TMessage); message UM_PRINT_DIALOG;

...

procedure TForm1.Button1Click(Sender: TObject);
begin
  InvoiceReport.ShowReport;
  //if you want to show the report once it is fully rendered use:
  //InvoiceReport.PrepareReport;
  //InvoiceReport.ShowPreparedReport;
end;

procedure TForm1.InvoiceReportPreview(Sender: TObject);
begin
  PostMessage(Handle,UM_PRINT_DIALOG,0,0);
end;

procedure TForm1.ShowPrintDialog(var Message: TMessage);
begin
  InvoiceReport.PrintOptions.ShowDialog:=True;
  InvoiceReport.Print;
end;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...