#1 2024-05-07 14:31:49

HansVM
Member
Registered: 2024-05-07
Posts: 5

SynPdf library 1.18 Delphi QuickReport 6 Pro and ExpBarChart error

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

#2 2024-05-08 09:50:06

rvk
Member
Registered: 2022-04-14
Posts: 111

Re: SynPdf library 1.18 Delphi QuickReport 6 Pro and ExpBarChart error

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

#3 2024-05-08 15:00:04

HansVM
Member
Registered: 2024-05-07
Posts: 5

Re: SynPdf library 1.18 Delphi QuickReport 6 Pro and ExpBarChart error

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

#4 2024-05-08 15:36:46

ttomas
Member
Registered: 2013-03-08
Posts: 131

Re: SynPdf library 1.18 Delphi QuickReport 6 Pro and ExpBarChart error

Offline

#5 2024-05-08 16:27:44

rvk
Member
Registered: 2022-04-14
Posts: 111

Re: SynPdf library 1.18 Delphi QuickReport 6 Pro and ExpBarChart error

HansVM wrote:

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

#6 2024-05-08 17:22:28

HansVM
Member
Registered: 2024-05-07
Posts: 5

Re: SynPdf library 1.18 Delphi QuickReport 6 Pro and ExpBarChart error

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

#7 2024-05-08 17:51:26

rvk
Member
Registered: 2022-04-14
Posts: 111

Re: SynPdf library 1.18 Delphi QuickReport 6 Pro and ExpBarChart error

HansVM wrote:

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

#8 2024-05-08 18:08:45

HansVM
Member
Registered: 2024-05-07
Posts: 5

Re: SynPdf library 1.18 Delphi QuickReport 6 Pro and ExpBarChart error

Can you give me a example of the code you sugested?

Offline

#9 2024-05-08 18:17:56

rvk
Member
Registered: 2022-04-14
Posts: 111

Re: SynPdf library 1.18 Delphi QuickReport 6 Pro and ExpBarChart error

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

#10 2024-05-09 16:59:30

HansVM
Member
Registered: 2024-05-07
Posts: 5

Re: SynPdf library 1.18 Delphi QuickReport 6 Pro and ExpBarChart error

Thanks for the help.

Offline

#11 2024-05-09 17:20:14

rvk
Member
Registered: 2022-04-14
Posts: 111

Re: SynPdf library 1.18 Delphi QuickReport 6 Pro and ExpBarChart error

O, and the i + 1 should just be i in your case smile
(You start at 1, not 0)

Offline

Board footer

Powered by FluxBB