How to change the printer in FR ?

类别:编程语言 点击:0 评论:0 推荐:

Q:
I can get the printer(s) List by using Delphi 6 Pro as the following code.

uses
printers

ComboBox1.Items.Assign(Printer.Printers);

But, I don't know how to change the properity of a frReport for the user selection!
The default printer selection dialog cannot be made a filter for our need ( e.g. print to a Fax printer, PDF printer, PostScript enabled printer or Dot-Martix printer ).
Would you give me some advice ?


A:
Use the TFRReport.ChangePrinter(OldIndex,NewInde:Integer):Boolean
function to change the output printer without using any customizable
printer setting dialogs. The parameters are the same as the reference
indexes in the Printer.Printers array. My preferred way to implement
this on the GUI: populate a combobox with the Printer.Printers list and
then let the user choose one from the list.

So:

Uses System,....,...,Printers;

YourForm.OnCreate(Sender:TObject);
Begin
PrinterCombo.Items.Assign(Printer.Printers);
End;

TYourForm.PrintButtonClick(Sender:TObject);
Begin
Report.LoadFromFile(...);
Report.ChangePrinter(-1, PrinterCombo.ItemIndex);
Report.Prepare;
...etc.
End;

-1 for the OldIndex parameter cause the report to use the original
index, so You don't need to know the previous index.

本文地址:http://com.8s8s.com/it/it24247.htm