Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Acrobat Reader ActiveX Access Violation on form close

My Delphi application has a form that uses the Acrobat Reader ActiveX control for viewing pdfs. When I use the control's functions (LoadFile, gotoNextPage, gotoPreviousPage, gotoFirstPage, gotoLastPage), then close the form, I get the following error: "Access violation at address 6AF5703C. Read of address 6AF5703C". When I run the app, but do not use the control's functions, and then close the form, the app will exit without error.

Anyone know of a fix or workaround for this issue?

My app is written using Delphi 5 (legacy app). I have Adobe Acrobat Reader DC v15.016.20045 installed.

like image 404
mcdon Avatar asked Jun 17 '16 16:06

mcdon


People also ask

Why Adobe PDF is closing automatically?

We're sorry for the trouble you had with Adobe Reader, please reboot the machine once and navigate to Adobe Reader's preferences from Edit>Preferences>Security(Enhanced)>and try disabling 'Enable Protected Mode at startup'>Click OK and restart the application and check.

Why does my PDF document keep closing?

When Adobe Reader is crashing, it is likely that either your tool build is faulty, or it is outdated. Adobe Acrobat keeps crashing in Windows 10 also when it runs in Protected Mode. The tool includes a repair function that you can use to fix crashing instances.

How do I force close in Acrobat?

Select the "Applications" tab. Select Adobe Acrobat from the list and click "End Task."


2 Answers

As I said in a comment to Zam, with the current version downloaded today of Acrobat Reader DC , I get the exact same error as you.

Please try this code and let us know whether it avoids the error for you, because it certainly works for me and there is no AV, either in the FormClose or afterwards.

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
  Ref : Integer;
begin
  Ref := AcroPdf1.ControlInterface._AddRef;
  AcroPdf1.Src := '';
  AcroPdf1.Free;
  AcroPdf1 := Nil;
end;

This is my FormCreate, which contains my only other code.

procedure TForm1.FormCreate(Sender: TObject);
begin
  AFileName := 'd:\aaad7\pdf\printed.pdf';
  AcroPdf1.src := AFileName;
  AcroPdf1.setZoom(200);  // <- this line is to exercise the
    // ControlInterface to provoke the AV on shutdown
end;

I have absolutely no idea why my FormClose avoids the AV problem, and before anybody else says so, yes, it looks mad to me, too! Hardly something that deserves the name "solution", but maybe it will suggest a proper solution to someone who knows more about COM and Ole controls than I do.

I originally included the Ref := AcroPdf1._AddRef just as an experiment. I noticed that after it, Ref's value was 9. After AcroPdf1.Src := '', calling AcroPdf1._Release in the debugger evaluator returned a value of 4. I was about to see if the AV was avoided by forcing the RefCount down by repeatedly calling _Release but then Presto!, there was no AV after my first trace into FormClose exited.

Update: I have not tested the following exhaustively, but this simplified FormClose also avoids the AV, on my system at any rate:

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
  Ref : Integer;
begin
  Ref := AcroPdf1.ControlInterface._AddRef;
end;

Obviously, omitting the assignment to Ref shouldn't make any difference.

I'm using Delphi 10 Seattle on 64-bit Win10, btw.

like image 182
MartynA Avatar answered Oct 10 '22 00:10

MartynA


The better solution is to edit the TPDF Object in "AcroPDFLib_Tlb.pas"

Just add the proper destructor to the Code to free the OLE Object:

Declaration

Type
  TAcroPDF = class(TOleControl)
  ...
  public
    destructor Destroy; override; // <- New Line
  ...
  end;

Implementation

destructor TAcroPDF.Destroy;
begin
 FIntf := NIL;
 inherited;
end;
like image 27
Thomas Ausweger Avatar answered Oct 10 '22 00:10

Thomas Ausweger