Issue with document closing event chain  SOLVED

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
User avatar
MartinCS
User
Posts: 153
Joined: Thu Apr 07, 2011 10:01 am
Contact:

Issue with document closing event chain

Post by MartinCS »

Hello Tracker-Team,

We have a situation where I have 2 tabs open in a custom control, and then attempt to close one of them (via the "x" button on the tab). However, when I look at what events are triggered by this action in the "PdfCtl_OnEvent" function, I see the following chain:
pdfCtl.OnEvent: EventID==2398 / EventDisplayName==e.document.beforeClose / CoreDoc.ID==65537
pdfCtl.OnEvent: EventID==2420 / EventDisplayName==e.document.modStateChanged / CoreDoc.ID==65537
pdfCtl.OnEvent: EventID==2397 / EventDisplayName==e.document.activated / CoreDoc.ID==65542
pdfCtl.OnEvent: EventID==2389 / EventDisplayName==e.activeDocChanged / CoreDoc.ID==65542
pdfCtl.OnEvent: EventID==2399 / EventDisplayName==e.document.closed / CoreDoc.ID==65542

As you can see, the "beforeclosed" event for document 65537 is triggered, but not the "closed" event. Strangely, a "closed" event is later triggered - however, this is for document 65542, which remains open in the control. It is worth noting that this behaviour occurs regardless of whether the tab being closed is the active tab or not. This is causing us problems, as we are not able to correctly communicate with our back-end system which document(s) have been edited and/or closed.

This problem gets worse when we attempt to close all open tabs simultaneously. To illustrate this problem, I opened 3 documents in the control, and then closed the main form of my application. Here is the output I received from the "PdfCtl_OnEvent" function:
pdfCtl.OnEvent: EventID==2398 / EventDisplayName==e.document.beforeClose / CoreDoc.ID==65545
pdfCtl.OnEvent: EventID==2420 / EventDisplayName==e.document.modStateChanged / CoreDoc.ID==65545
pdfCtl.OnEvent: EventID==2397 / EventDisplayName==e.document.activated / CoreDoc.ID==65544
pdfCtl.OnEvent: EventID==2389 / EventDisplayName==e.activeDocChanged / CoreDoc.ID==65544
pdfCtl.OnEvent: EventID==2399 / EventDisplayName==e.document.closed / CoreDoc.ID==65544
pdfCtl.OnEvent: EventID==2398 / EventDisplayName==e.document.beforeClose / CoreDoc.ID==65544
pdfCtl.OnEvent: EventID==2397 / EventDisplayName==e.document.activated / CoreDoc.ID==65542
pdfCtl.OnEvent: EventID==2389 / EventDisplayName==e.activeDocChanged / CoreDoc.ID==65542
pdfCtl.OnEvent: EventID==2399 / EventDisplayName==e.document.closed / CoreDoc.ID==65542
pdfCtl.OnEvent: EventID==2398 / EventDisplayName==e.document.beforeClose / CoreDoc.ID==65542

Again, the "closed" event is not triggered for the first document. However, in this case the "closed" event IS then triggered for the remaining 2 documents. However, for these documents the "beforeclosed" event is triggered AFTER the "closed" event. We are also finding that after this output is generated, we receive a System.NullReferenceException when trying to access the "pdfCtl.Doc.CoreDoc.ID" property (also in the "PdfCtl_OnEvent" function).

I am unsure why this is happening... Should you require any further details to help get to the bottom of this, please do let me know!

// Martin
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17824
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Issue with document closing event chain

Post by Tracker Supp-Stefan »

Hi Martin,

As for your other topic:
Alex is away till Monday, so he has asked me to let you know that he will be able to look at this once he is back!

Regards,
Stefan
User avatar
MartinCS
User
Posts: 153
Joined: Thu Apr 07, 2011 10:01 am
Contact:

Re: Issue with document closing event chain

Post by MartinCS »

Hi Stefan and Alex,

@Stefan: Thank you for the information.

I made some further investigations on that issue and might found the problem. Please find attached a sample project and a short video demonstrating the issue.

Here are the steps I perform in the video:
1.) I have two documents in tab mode opened
2.) I switch between these two documents and the corresponding ids (see messagebox) are correct (event: e.activeDocChanged)
3.) I close the tab with the x button which is not active at this time and I receive the id of the active document in the beforeclosing event
18-01-12_Sampleproject.zip
(1.24 MiB) Downloaded 83 times
I hope this information is of any help for your investigations.

// Martin
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Issue with document closing event chain  SOLVED

Post by Sasha - Tracker Dev Team »

Hello Marin,

I've investigated your sample. The problem is in this:

Code: Select all

 IPXV_Document doc = pdfCtl.Doc;
This will get the active document from the Control. If you are closing a document that is not currently active, then this code of your will still get the active document.
For the correct work of this, obtain the document from the event itself:

Code: Select all

PDFXEdit.IPXV_Document vDoc = (PDFXEdit.IPXV_Document)e.pFrom;
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
User avatar
MartinCS
User
Posts: 153
Joined: Thu Apr 07, 2011 10:01 am
Contact:

Re: Issue with document closing event chain

Post by MartinCS »

Hi Alex,

thank you for your help and clarification of the document Ids with the respective events! This solved my problems.

// Martin
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Issue with document closing event chain

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply