You are not logged in.
In Delphi 10.2 and Quick Report component TQRExpBarChart to PDF error.
procedure TfPrinterOptions.ExportAsPdf(QuickRep: TQRCompositeReport; aFileName, aDescription: String);
var
Pdf: TPdfDocument;
aMeta: TMetaFile;
i: integer;
pdfFilter: TQRPDFDocumentFilter;
begin
Pdf := TPdfDocument.Create;
Pdf.Info.CreationDate := Now;
if NOT dmVA.aQryVAPraktice.Active then
dmVA.aQryVAPraktice.Active := True;
Pdf.Info.Creator := dmVA.aQryVAPraktice.FieldByName('PrakticeName').AsString;
dmVA.aQryVAPraktice.Active := False;
Pdf.DefaultPaperSize := psA4;
QuickRep.Prepare;
try
for i := 1 to QuickRep.QRPrinter.PageCount do
begin
Pdf.AddPage;
aMeta := QuickRep.QRPrinter.GetPage(i);
try
// draw the page content
Pdf.Canvas.RenderMetaFile(aMeta,1,1,0,0);
finally
aMeta.Clear;
aMeta.Free;
end;
end;
Try
Pdf.SaveToFile(aFileName); // Error Access violation at address 004C4620 in module ...
Finally
// Send to ...
end;
finally
Pdf.CleanupInstance;
Pdf.free;
end;
Offline
You are using the older SynPDF? (Newer source is in mORMot2)
I can't spot the problem exactly... but you have a Pdf.CleanupInstance.
TObject.CleanupInstance should never be called directly.
The aMeta.Clear also seems useless (because that should also be done in aMeta.Free).
Remove those two lines and see if it helps.
Although the error doesn't seem to point to those places, it could be because of the try/finally (and exception handling).
Something like this:
procedure TfPrinterOptions.ExportAsPdf(QuickRep: TQRCompositeReport; aFileName, aDescription: String);
var
Pdf: TPdfDocument;
aMeta: TMetaFile;
i: integer;
pdfFilter: TQRPDFDocumentFilter;
begin
if NOT dmVA.aQryVAPraktice.Active then
dmVA.aQryVAPraktice.Active := True;
dmVA.aQryVAPraktice.Active := False;
QuickRep.Prepare;
Pdf := TPdfDocument.Create;
try
Pdf.Info.CreationDate := Now;
Pdf.Info.Creator := dmVA.aQryVAPraktice.FieldByName('PrakticeName').AsString;
Pdf.DefaultPaperSize := psA4;
for i := 1 to QuickRep.QRPrinter.PageCount do
begin
Pdf.AddPage;
aMeta := QuickRep.QRPrinter.GetPage(i);
try
// draw the page content
Pdf.Canvas.RenderMetaFile(aMeta,1,1,0,0);
finally
aMeta.Free;
end;
end;
try
Pdf.SaveToFile(aFileName); // Error Access violation at address 004C4620 in module ...
finally
// Send to ...
end;
finally
Pdf.free;
end;
end;
Offline
Ok I have installet the mORMot2.
But it will not have this line Pdf.Canvas.RenderMetaFile(aMeta,1,1,0,0);
This is the code I'm using now in mORMot2:
QuickRep.Prepare;
Pdf := TPdfDocument.Create;
Try
Pdf.Info.CreationDate := Now;
Pdf.Info.Creator := aPractiveName;
Pdf.DefaultPaperSize := psA4;
for i := 1 to QuickRep.QRPrinter.PageCount do
begin
Pdf.AddPage;
aMeta := QuickRep.QRPrinter.GetPage(i);
try
// draw the page content
Pdf.Canvas.RenderMetaFile(aMeta,1,1,0,0);
finally
aMeta.Free;
end;
end;
Try
Pdf.SaveToFile(aFileName);
Finally
End;
Finally
pdf.Free;
End
Last edited by HansVM (2024-05-08 16:18:43)
Offline
Offline
Ok I have installet the mORMot2.
But it will not have this line Pdf.Canvas.RenderMetaFile(aMeta,1,1,0,0);
No, there is no TPDFCanvas.RenderMetaFile.
But you should use procedure RenderMetaFile() for that.
It's in mormot.ui.pdf so you can just call it.
You pass your Pdf.Canvas as first parameter. Rest is the same.
procedure RenderMetaFile(C: TPdfCanvas; MF: TMetaFile; ScaleX: single = 1.0;
ScaleY: single = 0.0; XOff: single = 0.0; YOff: single = 0.0;
TextPositioning: TPdfCanvasRenderMetaFileTextPositioning = tpSetTextJustification;
KerningHScaleBottom: single = 99.0; KerningHScaleTop: single = 101.0;
TextClipping: TPdfCanvasRenderMetaFileTextClipping = tcAlwaysClip);
Last edited by rvk (2024-05-08 16:28:06)
Offline
Thanks for the help.
I still get the error on the quickreport.TQRExpBarChart in Delphi 10.2 and QReport V6 Pro.
If I print manual all is working,
If I preview all is working.
Only when I export by code it give me a eccess violation at address 01EF3D35.
When I debug the code all looks fine but still at random places it generate this error.
All my other reports are working fine exept the ones with this TQRExpBarChart component.
Last edited by HansVM (2024-05-08 17:23:45)
Offline
I still get the error on the quickreport.TQRExpBarChart in Delphi 10.2 and QReport V6 Pro.
If you are using the latest mORMot2, can you save the metafile to file and try loading it in a separate procedure.
If it still gives you problems maybe you can share that metafile.
(Just to rule out any potential problems in combination with TQRExpBarChart)
I used meta.LoadFromFile and RenderMetaFile() and that worked fine.
Offline
Can you give me a example of the code you sugested?
Offline
In your current code you can put a line like this:
meta.SaveToFile(format('c:\temp\meta-%d.emf', [i + 1])); // this saves the meta to c:\temp
// draw the page content
RenderMetaFile(Pdf.Canvas, aMeta,1,1,0,0); // <-- this is the old line
After that you can test with:
procedure TestMetaToPdf;
var
Pdf: TPdfDocument;
aMeta: TMetaFile;
begin
Pdf := TPdfDocument.Create;
try
Pdf.Info.CreationDate := Now;
Pdf.Info.Creator := 'meme';
Pdf.DefaultPaperSize := psA4;
Pdf.AddPage;
aMeta := TMetaFile.Create;
try
aMeta.LoadFromFile('c:\temp\meta-1.emf');
// draw the page content
RenderMetaFile(Pdf.Canvas, aMeta,1,1,0,0);
finally
aMeta.Free;
end;
try
Pdf.SaveToFile('c:\temp\test9.pdf');
finally
// Send to ...
end;
finally
Pdf.free;
end;
end;
Offline
Thanks for the help.
Offline
O, and the i + 1 should just be i in your case
(You start at 1, not 0)
Offline