354 crashes my app when "disabling" multiple bookmarks selection. 352 (and previous) works fine  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
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

354 crashes my app when "disabling" multiple bookmarks selection. 352 (and previous) works fine

Post by zarkogajic »

Hi Support,

In my attempt to disable the user to select multiple bookmarks - and only have one selected at a time.

I've been using this code (note: I'm actually using Delphi.):

Code: Select all

if (e.nEventID == nIDS[(int)IDS.e_docSelection_changed])
{
	IPXV_Document vDoc = (IPXV_Document)e.pFrom;

	if ((vDoc.ActiveSel != null) && (vDoc.ActiveSel.ID == pdfCtl.Inst.Str2ID("selection.bookmarks")))
	{
		IPXV_BookmSelection bmkSel = (IPXV_BookmSelection)vDoc.ActiveSel;
		bmkSel.Items.Remove(0, (uint)(-1 + bmkSel.Items.Count));
	}
}

In version 352 this worked fine. Version 354 crashes the application - and the crash happens after the code is executed (with some delay).

I'm attaching the sample app code. Please take a look and let me know how to fix....
pdfx-selection.zip
(52.66 KiB) Downloaded 58 times
p.s.
Does not only affect bookmarks selection. The same crash happens if "disable" (same coding) selecting multiple pages (IPXV_PagesSelection).



-žarko
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2351
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: 354 crashes my app when "disabling" multiple bookmarks selection. 352 (and previous) works fine

Post by Vasyl-Tracker Dev Team »

Hi žarko.

As I see the bmkSel.Items.Remove just returns E_INVALIDARG in case when bmkSel.Items.Count==0 and then on your side this E_INVALIDARG is thrown as an exception. So fix is easy:

Code: Select all

IPXV_BookmSelection bmkSel = (IPXV_BookmSelection)vDoc.ActiveSel;
if (bmkSel != null && bmkSel.Items.Count > 1)
      bmkSel.Items.Remove(0, (uint)(-1 + bmkSel.Items.Count));
Cheers.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: 354 crashes my app when "disabling" multiple bookmarks selection. 352 (and previous) works fine

Post by zarkogajic »

Hi Vasyl,

Thanks, but unfortunately that does not help.

In my provided sample app I have the check for Items.Count > 0.

Also: no exception, the app just vanishes with a delay.

User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2351
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: 354 crashes my app when "disabling" multiple bookmarks selection. 352 (and previous) works fine

Post by Vasyl-Tracker Dev Team »

Hi žarko.

Unfortunately, but I cannot reproduce crash you have. I tried it with the modified FullDemo(C#), with added:

Code: Select all

if (e.nEventID == nIDS[(int)IDS.e_docSelection_changed])
{
	PDFXEdit.IPXV_Document doc = (PDFXEdit.IPXV_Document)e.pFrom;
	if (doc != null)
	{
		PDFXEdit.IPXV_DocSelection docSel = doc.ActiveSel;
		if (docSel != null && !docSel.IsEmpty)
        	{
			if (docSel.ID == pdfCtl.Inst.Str2ID("selection.bookmarks", false))
            		{
				PDFXEdit.IPXV_BookmSelection bmkSel = (PDFXEdit.IPXV_BookmSelection)docSel;
				if (bmkSel != null && bmkSel.Items.Count > 1)
		                {
					bmkSel.Items.Remove(0, (uint)(-1 + bmkSel.Items.Count));
				}
			}
		}
	} 
}
- and no any crash at all. Will ask my colleague to try your Delphi-sample...

However, seems I can suggest other and maybe better way to do what you want. You may try to modify the tree/list-control styles to remove MultSel-flag. For example I tried it in modified FullDemo by this code:

Code: Select all

public partial class UIEventDemoMon : PDFXEdit.IUIX_EventMonitor
{
	public void OnEventMonitor(PDFXEdit.IUIX_Obj pTarget, PDFXEdit.IUIX_Event pEvent)
	{
		if (pEvent.Code == (int)PDFXEdit.UIX_EventCodes.e_Visible)
       		{
			if (pTarget.ID == pTarget.ThreadCtx.Inst.Str2ID("bookmarksView", false))
			{
				IntPtr nTreeImplIntPtr = IntPtr.Zero;
				Type t = typeof(PDFXEdit.IUIX_Tree);
				pTarget.QueryImpl(t.GUID, null, out nTreeImplIntPtr);
				if (nTreeImplIntPtr != IntPtr.Zero)  // check if it is the true tree-control and not its scroll container which may have the same ID
                		{
					System.Runtime.InteropServices.Marshal.Release(nTreeImplIntPtr);
					pTarget.SetStyle(0, (int)PDFXEdit.UIX_TreeStyleFlags.UIX_TreeStyle_MultSel);
				}
			}
		}
	}
}
- and it works well for me..

HTH
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: 354 crashes my app when "disabling" multiple bookmarks selection. 352 (and previous) works fine  SOLVED

Post by zarkogajic »

Hi Vasyl,

Yes, the crash is only in Delphi, so please let your Delphi guy check that.

Big thanks for "UIX_TreeStyle_MultSel" - I was not aware of it - and that would be the best approach.

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

Re: 354 crashes my app when "disabling" multiple bookmarks selection. 352 (and previous) works fine

Post by Sasha - Tracker Dev Team »

Hello zarkogajic,

We'll forward that to him.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply