Page 1 of 1

Issue with document closing event chain

Posted: Thu Jan 11, 2018 9:05 am
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

Re: Issue with document closing event chain

Posted: Fri Jan 12, 2018 1:05 pm
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

Re: Issue with document closing event chain

Posted: Fri Jan 12, 2018 1:48 pm
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
I hope this information is of any help for your investigations.

// Martin

Re: Issue with document closing event chain  SOLVED

Posted: Mon Jan 15, 2018 10:43 am
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

Re: Issue with document closing event chain

Posted: Tue Jan 16, 2018 5:19 am
by MartinCS
Hi Alex,

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

// Martin

Re: Issue with document closing event chain

Posted: Tue Jan 16, 2018 8:00 am
by Sasha - Tracker Dev Team
:)