Board index » delphi » Quick Report: loading .QRP file

Quick Report: loading .QRP file

I'm using Delphi 3 with Quick Report version 2. How do you load a
quick report file ( *.QRP) and then preview it by using code? I don't
want to use the load icon in the Preview form. Appreciate any help on
this problem.
 

Re:Quick Report: loading .QRP file


Maybe the following code will help. It's the source code for a delphi
project which will preview the .QRP file passed as the first parameter.

Marc
program QRViewer;

uses
  CommDlg, QuickRep, SysUtils, Forms,Printers;

var
  fn      : String;

{$R *.RES}

function RequestFn : String;
var
  od        :  tOpenFileName;
const
  MaxFile   =  256;
  DefExt    =  '*.qrp';
  StrFilter =  'QuickReport Files (*.qrp)'#0'*.QRP'#0+
               'All Files (*.*)'#0'*.*'#0#0;
begin
  SetLength(result, MaxFile);
  result[1]      := #0;
  od.lStructSize       := SizeOf(tOpenFileName);
  od.hWndOwner         := Application.Handle;
  od.hInstance         := hInstance;
  od.lpStrFilter       := pChar(StrFilter);
  od.lpStrCustomFilter := nil;
  od.nFilterIndex      := 1;
  od.lpStrFile         := pChar(result);
  od.nMaxFile          := MaxFile;
  od.lpStrFileTitle    := nil;
  od.lpStrInitialDir   := nil;
  od.lpStrTitle        := nil;
  od.lpStrDefExt       := pChar(DefExt);
  od.flags :=  OFN_Explorer  or OFN_FileMustExist
            or OFN_Longnames or OFN_ShareAware;

  if not GetOpenFileName(od)
     then halt(1);
end;

begin
Application.Title := 'Quick Report Viewer';
{$IFDEF NOTHING}  {This section is needed to allow editing}
  Application.Initialize;
  Application.CreateForm(Form1, tForm1);
  Application.Run;
{$ENDIF}

  {Get the filename}
  if ParamStr(1)=''
     then fn := RequestFn
     else fn := ParamStr(1);

  Application.Title := ExtractFileName(fn) + ' - Quick Report';

  {Choose the correct printer}
  if ParamStr(3) <> '' then
     Printer.PrinterIndex :=
           Printer.Printers.IndexOf( Format('%s on %s', [ParamStr(3),
ParamStr(5)] ) );

  {Print / Preview}
  with QRPrinter do
    begin
      Title := Application.Title;
      EnableSaveBtn := False;
      Load(fn);
      // Thumbs := ...
      if (UpperCase(ParamStr(2))='/P') or (UpperCase(ParamStr(2))='-P')
        then Print
        else Preview;
      CleanUp;
    end;
end.

Other Threads