Home Devices
New Blog Posts: Merging Reports - Part 1 and Part 2

TppArchiveReader.Print() to PDF causes access violation on third time

edited February 2013 in Devices
We've been having problems converting reports to PDFs. We create the
reports and save them as text files which are then, one by one, converted to
PDFs. We use the TppArchiveReader to convert the report data files to PDFs.
The issue is that we get an access violation during the
ArchiveReader.Print() method.

I've found on my computer (Windows Vista, RB 14.08) that it always access
violates on the third PDF print. This is only an issue on some computers.
So far the computers that have had an issue have been either XP or Vista
operating systems. We also spotted that using remote desktop into a
customer's computer it was fine when we logged in with a Windows 7 computer
but had the issue again when logging into the same machine from a Windows XP
computer.

We've been doing some debugging into the Report Builder source code and it
doesn't always crash in the same place but most often does so in
TppEmailSettings.Destroy() from the TppProducer.FinalizePrintToPrinter()
method. It tries to free FBodyHTML, which is not nil, but then access
violates.

This is the code that we use to convert the report data files into PDFs
(using RB 14.08):

procedure TForm1.PrintArchives;
var TempFileName : String;
sr : TSearchRec;
begin
try
TempFileName := ExtractFilePath(Application.ExeName) + 'Archives\';
if findFirst(TempFilename+'*.txt', faAnyFile, sr) = 0 then
begin
// Convert them to PDF in turn
repeat
if (sr.Attr and faAnyFile) = sr.Attr then
begin
MessageDlg('Printing ' + sr.Name, mtInformation, [mbOK], 0);

ArchiveReader.ArchiveFileName := ExtractFilePath(TempFileName) +
sr.Name;
ArchiveReader.TextFileName := ExtractFilePath(TempFileName) +
ChangeFileExt(sr.Name, '.pdf');
ArchiveReader.ShowCancelDialog := False;
ArchiveReader.PDFSettings.FontEncoding := feUnicode;
ArchiveReader.PDFSettings.EmbedFontOptions := [efUseSubset];
ArchiveReader.Print;
application.processmessages;
ArchiveReader.Reset;
DeleteFile(ArchiveReader.TextFileName);
end;
until FindNext(sr) <> 0;

FindClose(sr);
end;

MessageDlg('All reports done!', mtInformation, [mbOK], 0);

except on e: Exception do
MessageDlg(sr.Name + '. Error:' +#13+#13+ e.Message, mtError, [mbOK],
0);
end;
end;

We've got a sample application to demonstrate this issue so if you require
this then please let me know. If anyone could help with this issue we would
be very grateful!

Thanks,
Farran

Comments

This discussion has been closed.