Error closing form with TAcroPDF in Delphi

3

This "blessed" component, unfortunately I need to use it, it happens that whenever I try to close the Form it closes, but always gives an AccessViolation .

There is nothing in the Form besides a TAcroPDF and a Close button.

The impression is that the form is being closed before destroying the component, I happen to have already tried FreeAndNil(AcroPDF1); AcroPDF.Free; AcroPDF.Destroy etc etc ... and nothing, they insist on giving the AccessViolation .

I put the Form construction inside a Try to solve the problem, but it is not the correct way, whenever I need to move this Form at development time, here comes the damn Accessviolation.

Has anyone had this and solved it?

Obs: I solved this problem on another screen using TWebbrowser to open PDF, but I use this TAcroPDF in several screens and would have to rewrite them, causing other problems in the application since this TWebbrowser is also a annoying component to move before from radical departure I would like to know if there is a more friendly solution for TAcroPDF.

    
asked by anonymous 26.03.2018 / 17:31

1 answer

5

Destruction should occur as soon as Form invokes Destroy of its "children."

What happens in this case is that one of your children is not an instantiated object, but initialized, which usually occurs in some ActiveX components.

In some cases it is only resolved by including in the Create of the Form a CoInitialize that will instantiate all ActiveX Objects, and in Close trigger CoUnitialize that in turn will remove all ActoveX interface.

In the case of AcroPdf, it is not an object that can be destroyed next to the interface, so we need to warn you that it needs to be destroyed.

I found SOEn in a solution that, incredible, seems to work for a long time.

No close:

AcroPdf1.ControlInterface._AddRef;

In this way it will invoke the _Release of the component, it is no use invoking the _Release directly, there are internal processes of the application that must be performed for the done, such as its own release of allocated memory.

It's not your Application's fault or the component, it's Delphi's own fault that allows objects to be created without a well-made Class creation. I mean, there is a Construtor and there is no Destructor .

It's worth remembering that this component in VB.6 does not happen that often.

Similar question.

    
27.03.2018 / 14:45