Quickreport 4. Access violation in qrprinter printing from page to page

Quickreport 4. Access violation in qrprinter printing from page to page

Post by Roberto Ni » Thu, 08 May 2008 18:43:35


I'm porting my application from Delphi 7 to Delphi 2007 and have replaced QR
3 with QR 4 (standard)

In my application i have some reports that are created using a Tqrprinter

Have also a custom preview with a print button.

If i print all pages i have no problem but if i want to print a page
selection (from page to page) have an access violation.

I'm using the code above to print from page to page. An access violation
occurs in the PRINT line. Does someone have a working code ?

thank you

Roberto

SrcFileName := TempFileName;
DestFileName := TempFileName;
CopyFileName := TempFileName;

// Save the report to a file so that we can work with it.
qrprinter.Save(SrcFileName);

// Build a new file with the range of pages that was selected
RangeFromQRP(SrcFileName, DestFileName, printdialog.FromPage,
printdialog.ToPage);

with TQRPrinter.Create(nil) do
begin
printerindex := printer.printerIndex;

pp:=Tprinterparams.create;
try
GetPrinterParams(pp);
qrprinter.UseCustomBinCode:=true;
qrprinter.CustomBinCode := pp.Bin;
finally
pp.free;
end;

// If we want more than 1 copy, we just repeat the pages in the
// list. This will make sure that only a single print job is
// issued.
if printdialog.Copies > 1 then begin
CopyList := TStringList.Create;

for i := 1 to printdialog.copies do
CopyList.Add(DestFileName);

CombineQRP(CopyFileName, CopyList);

CopyList.Free;

Load(CopyFileName);
end
else
Load(DestFileName);

Print; <...................... ACCESS VIOLATION HERE

Free;
end;
DeleteFile(CopyFileName);
DeleteFile(DestFileName);
DeleteFile(SrcFileName);
 
 
 

Quickreport 4. Access violation in qrprinter printing from page to page

Post by Roberto Ni » Tue, 20 May 2008 18:49:07

For who is interested in the following code should works:

var
i: integer;
RepeatPrint: boolean;
begin
printer.PrinterIndex := qrprinter.printerindex;

printdialog.options:=[poPagenums];
printdialog.frompage:=1;
printdialog.minpage:=1;
printdialog.topage:=QRPrinter.PageCount;
printdialog.maxpage:=QRPrinter.PageCount;

if printdialog.execute then
begin
qrprinter.PrinterIndex:=printer.PrinterIndex;

if printdialog.PrintRange=prPagenums then
begin
qrprinter.FirstPage:=printdialog.FromPage;
qrprinter.lastpage:=printdialog.ToPage;
end
else begin
qrprinter.FirstPage:=0;
qrprinter.lastpage:=0;
end;

qrprinter.Copies:=printdialog.Copies;

repeatprint:=false;
if printdialog.copies>1 then
if qrprinter.copies=1 then repeatprint:=true;

if repeatprint then
begin
for i:=1 to printdialog.copies do
qrprinter.Print;
end
else qrprinter.Print;
end;
end;


"Roberto Nicchi" < XXXX@XXXXX.COM > ha scritto nel messaggio