I have an odd problem and I thought I'd ask here to see if anyone else has seen it. The following code should compile with minimal change:
Code: Select all
procedure TestPdfDoc(const AFilename: string); var idoc: IPXC_Document; page: IPXC_Page; i, count: DWORD; begin // PdfXInst is a PXC_Inst global in this test unit idoc := PdfXInst.OpenDocumentFromFile(PChar(AFilename), nil, nil, 0, 0); if Assigned(idoc) then begin idoc.Pages.Get_Count(count); for i := 0 to count - 1 do begin idoc.Pages.Get_Item(i, page); end; idoc.Close(0); page := nil; idoc := nil; // <<<<< If this line exists end; end; // <<<<< Access violation here
But it only happens with IPXC_Document variables. The IPXC_Page variable in the example is quite happy with its redundant clean up. Does that make it a CORE API SDK bug? Or maybe someone here will try this with the same version of Delphi and won't see the problem, making it all my problem.
In the above example, you can leave "idoc := nil;" in the code if you take out the Pages.Get_Count and Pages.Get_Item loop. So there would seem to be something that happens in the SDK that alters Delphi's behaviour at clean up. Any guesses?
P.S. This is not a urgent problem for me. The assignment to nil truly is redundant, even in my original code. (I was trying it out to see if idoc was holding a file open (it wasn't) when I found this error.) So not urgent but I would like to resolve it, or at least work how where it's coming from.
Edited to Add: My PdfXInst is a PXC_Inst global is created via loadlibrary and calling PXC_GetInstance (not via a registered COM server). Just in case that makes a difference.