Missing metafiles in PDF export when run in thread
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:
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:
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!