The QRP File Handler class TQRPHandler in QRExtra.pas


Saved reports can be swiftly printed or displayed with this code -

uses qrextra;
procedure HandleQRPFile(ReportFile: String; ToPrint: Boolean);
var
  QRPDevice: TQRPHandler;
begin
     QRPDevice := TQRPHandler.Create;
     try
        QRPDevice.Filename := ReportFile;
        if ToPrint then
             QRPDevice.Print
        else
             QRPDevice.Preview;
     finally
         QRPDevice.Free;
     end;
end;

An extension to the QRPHandler class that sends to a selected printer.
----------------------------------------------------------------------

Add this new method in qrextra.pas.

  TQRPHandler = class
    private
      // add this private var
      FPIndex : integer;
      ..
    public
       // new public method - call it what you will
       // params : QRP file to send, destination printer index.
       procedure SendFile( pfilename : string; PIndex : integer);
       ..
       ..
  end;


implementation

procedure TQRPHandler.SendFile( pfilename : string; PIndex : integer);
begin
    if assigned(FQRPrinter) then FQRPrinter.Free;
    FQRPrinter := TQRPrinter.Create;
    if FQRPrinter.PrinterIndex <> PIndex then
                  FQRPrinter.PrinterIndex := PIndex;
    FPIndex := PIndex;
    FFilename := pfilename;
    FQRPrinter.Load(FFilename);
    FQRPrinter.Print;
end;

--------------------------------------------------------------------------

Example code using the SendFile method -

procedure SendaFile(ReportFile: String);
var
   QRPDevice: TQRPHandler;
   SelectedPrinterIndex : integer;
begin
     // Add some code to set the printer index for destination
     // e.g. a printer setup dialog
     SelectedPrinterIndex := ?????
     QRPDevice := TQRPHandler.Create;
     try
         QRPDevice.SendFile( ReportFile, SelectedPrinterIndex );
     finally
         QRPDevice.Free;
     end;
end;