Missing metafiles in PDF export when run in thread

edited 11:16AM in FastReport 3.0
Hi,

I have need to include several TChart charts on reports. The charts can have tens of thousands of values in single series. The TCharts are included in reports like this:
void TReportGeneratorForm::setChart(const TfrxReport *frxReport, AnsiString object,TChart *chart)
{
  TfrxPictureView *Picture;
  TMetafile *metafile;
  Picture = (TfrxPictureView*)frxReport->FindObject(object);
  TRect rect(0,0,chart->Width,chart->Height);
  metafile = chart->TeeCreateMetafile(true,rect);
  Picture->Picture->Assign(metafile);
  delete metafile;
}
Because of the vast amount of series values on the TChart's, the metafile is enormous in size and exporting the report to PDF therefore takes some time. During report generation I want to application to be responsive and to give the user possibility to abort the report generation. Obviously this requires the report generation to take place in a separate thread.

However, when I placed the report generation methods in a class inherited from TThread, occasionally the charts disappeared from PDF files or some parts of the series were missing. I debugged the code and the TCharts are refreshed properly and that above code is executed as supposed. I suspect the PDF export is guilty. It sometimes fails to include the metafile in PDF file when run in thread.

The exporting is done like this:
void TReportGeneratorForm::prepareAndExportReport(TfrxReport *report, AnsiString destination, bool open)
{
  report->PrepareReport(true);
  report->ShowProgress = false;
  frxPDFExport->FileName = destination;
  frxPDFExport->OpenAfterExport = open;
  report->Export(frxPDFExport);
}
When the same code is used and the report generation is not done in thread everything works ok!

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.