title: How to close PDF document that is used in Acrobat Reader ActiveX component from Delphi?
body: <p>I have importated Acrobate Reader ActiveX component in my Delphi application and loaded PDF document with code:</p>
  <pre><code>var AA: TAcroPDF;
  
  function GetFilePath(AFileName: String): String;
  begin
    Result:=IncludeTrailingPathDelimiter(ExtractFileDir(Application.ExeName))+AFileName;
  end;
  
  procedure TMainForm.Open2BtnClick(Sender: TObject);
  var FPath: String;
  begin
    FPath:=GetFilePath('test.pdf');
    if not FileExists(FPath) then raise Exception.Create('No file');
  
    AA.LoadFile(FPath);
  end; 
  </code></pre>
  <p>But I can not unload PDF file from Acrobat ActiveX component. My use case requires that component unloads the file and shows gray rectangle upon the request from user. I have tried several code lines:</p>
  <pre><code>AA.Src:='';
  AA.LoadFile('');
  </code></pre>
  <p>But file stays loaded all the time. I can successfully call the load of another file, but I can not find the way to unload the file.</p>
  <p>I am using Delphi 2009, but I guess that my question applies to any version.</p>
  <p><strong>Question update and suggestion of hack as a solution</strong>:</p>
  <p>I managed to adapt the code from <a href="https://stackoverflow.com/a/37889375/1375882">https://stackoverflow.com/a/37889375/1375882</a> as for the close:</p>
  <pre><code>procedure TMainForm.Close1BtnClick(Sender: TObject);
  var
    Ref : Integer;
  begin
    if Assigned(AA) then begin
      Ref:=AA.ControlInterface._AddRef;
      AA.Src:='';
      AA.Free;
      AA:=Nil;
    end;
  end;
  </code></pre>
  <p>And accordingly I am checking <code>if Assigned(AA)</code> in <code>FormClose</code> as well. This works perfectly for me as far as I can see. But this seems to be no clean solution that was intended by Acrobat Reader?</p>
  <p><strong>Bad consequences of the suggested hack/solution</strong>:</p>
  <p>No dark-gray rectangle remains on the form after onloading Acrobat Reader component in the suggested way and the subsequent call of anothes <code>LoadFile(...)</code> fails with AV, of course.</p>