Link (gotor/launch) navigation events + a few questions + an AV in Delphi  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: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Link (gotor/launch) navigation events + a few questions + an AV in Delphi

Post by zarkogajic »

Hi devs,

I have a pdf document with a link to another existing document and to a non existing document. Using Delphi.

image.png

Clicking the link "link to destination" - brings the "Open Document Warning" dialog.
image.png
  • How to disable this dialog from opening?
  • How to react to the "link navigation event" - get the target document (path) and cancel it if needed?
Clicking the link "link to missing document" does nothing (as the target is missing - so "invalid" link).
  • How to react to the "link navigation event" - get the target document (path) and bring my own custom dialog saying the link is dead.
Next, by default Docs.SingleWnd is true - clicking the first link will open the destination document in the same "window" but an AV happens.
If Docs.SingleWnd = false and Docs.OpenRelDocTabMode = 2 (same tab), the destination document does get open but an AV happens.
image.png
If Docs.SingleWnd = false and Docs.OpenRelDocTabMode = 0 (new tab) - no AV and all works as expected (destination document opens in new tab).

I'm attaching a sample Delphi project to test by your Delphi-guy.
pdfxchange-link-navigation.zip
(100.61 KiB) Downloaded 65 times
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Re: Link (gotor/launch) navigation events + a few questions + an AV in Delphi

Post by zarkogajic »

Hi devs,

To answer some of my questions :)
How to react to the "link navigation event" - get the target document (path) and cancel it if needed?
This involves doing what's described here: viewtopic.php?f=66&t=31749&p=129710&hil ... nt#p129115

And some Delphi code for those in the need:

Code: Select all

procedure TMainForm.PXV_Control1Event(ASender: TObject; nEventID: Integer; const pEvent: IEvent; const pFrom: IInterface);
var
  action  : IPXC_Action;
  atomGOTO, atomGOTOR, atomLink : LongWord;
  docActionEvent : IPXV_DocActionEvent;
  annot : IPXC_Annotation;
  annotType, actType : Cardinal;
  actionGOTO : IPXC_Action_Goto;
  fileSpec : IPXC_FileSpec;
  targetFileName : WideString;
  fileName : string;
begin
  atomLINK := IPXS_Inst(PXV_Control1.Inst.GetExtension('PXS')).StrToAtom('Link');
  atomGOTO := IPXS_Inst(PXV_Control1.Inst.GetExtension('PXS')).StrToAtom('GoTo');
  atomGOTOR := IPXS_Inst(PXV_Control1.Inst.GetExtension('PXS')).StrToAtom('GoToR');

  if nEventID = e_document_beforeRunAction then
  begin
    docActionEvent := IPXV_DocActionEvent(pEvent);

    if docActionEvent.TriggerClass = PAEC_Link then
    begin
      action := docActionEvent.Action;
      annot := IPXC_Annotation(docActionEvent.ActionData);

      annot.Get_type_(annotType);

      if annotType <> atomLink then
      begin
        ShowMessage('we have a weird moment here!');
        Exit;
      end;

      action.Get_type_(actType);

      if actType = atomGOTOR then
      begin
        actionGOTO := IPXC_Action_Goto(action);

        actionGOTO.Get_Target(fileSpec);

        fileSpec.Get_FileName(targetFileName);

        //this stops the action from being executed (and the "Open Document Warning" dialog from being displayed
        pEvent.Handled := true;
        pEvent.Result := 1; //non 0, can use with e.document.afterRunAction

        //open the target document "manually"
        fileName := TPath.Combine(ExtractFileDir(PXV_Control1.src), targetFileName);
        PXV_Control1.OpenDocFromPath(fileName, nil);
      end;
    end;
  end;
end;

Still the question remains: is there a way to disable that "Open Document Warning" dialog - without doing all this coding...

And also, what do do with that Access Violation when opening a target document in the same "tab".

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

Re: Link (gotor/launch) navigation events + a few questions + an AV in Delphi

Post by Sasha - Tracker Dev Team »

Hello žarko,

For precise logic for the needed action, you can use the custom implementation of the https://sdkhelp.pdf-xchange.com/vi ... ionHandler while storing the old handler as a variable inside, so that the class would act as a listener. Then you can call all of the old handler's methods inside of the corresponded methods of the class, and do some checks before that and break if needed.

As for the dialog suppression - you can disable this:
image.png
If this works for you - I can give you the needed settings field IDs.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Re: Link (gotor/launch) navigation events + a few questions + an AV in Delphi

Post by zarkogajic »

Hi Alex,

Thanks. Any code samples for the ActionHandler implementation?

Yes, please provide setting IDs

p.s.
Your image does not display.

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

Re: Link (gotor/launch) navigation events + a few questions + an AV in Delphi

Post by Sasha - Tracker Dev Team »

Hello žarko,

No samples for the ActionHandler - should be simple like command handler class.
And also, updated the screenshot - try first and tell the fields you need.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Re: Link (gotor/launch) navigation events + a few questions + an AV in Delphi

Post by zarkogajic »

Hi Alex,
image.png
image.png (38.04 KiB) Viewed 4203 times
and
image.png
image.png (31.48 KiB) Viewed 4203 times
p.s.
What about that AV in Delphi when navigating do the hyperlinked document in the same tab?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Link (gotor/launch) navigation events + a few questions + an AV in Delphi

Post by Sasha - Tracker Dev Team »

Hello žarko,

We've tried investigating your Delphi sample with or without the SingleWnd flag specified - no luck finding the AV. We clicked Link Same Tab in different combinations (after opened the source file) - no luck.

As for the needed settings IDs:
Security.OpenFilePerm = 1 //Allow it
Security.OpenFilePerm = 3 //Allow PDF(s) and use Trusted/Untrusted list for others

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Re: Link (gotor/launch) navigation events + a few questions + an AV in Delphi

Post by zarkogajic »

Hi Alex,
We've tried investigating your Delphi sample with or without the SingleWnd flag specified - no luck finding the AV. We clicked Link Same Tab in different combinations (after opened the source file) - no luck.
What Delphi version are you using? I'm testing with Delphi 10 Seattle.
What version of SDK? My SDK file version is 8.0.332.0.

Anyhow I just tried creating a simplest possible scenario: new project, one main form, drop control on it. Have a button to load a file with a link. Click. Link opens a document + AV.

Attached the video.
av in link navigation.zip
(1.54 MiB) Downloaded 62 times
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Link (gotor/launch) navigation events + a few questions + an AV in Delphi

Post by Sasha - Tracker Dev Team »

Hello žarko,

Strange, he uses the same Delphi version as you are.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Re: Link (gotor/launch) navigation events + a few questions + an AV in Delphi

Post by zarkogajic »

Alex,

"works on my machine" will not help here :)

As you can see from the video the AV is there - and no special coding involved.



zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Re: Link (gotor/launch) navigation events + a few questions + an AV in Delphi

Post by zarkogajic »

Alex,
Sasha - Tracker Dev Team wrote: Tue Sep 24, 2019 8:48 am For precise logic for the needed action, you can use the custom implementation of the https://sdkhelp.pdf-xchange.com/vi ... ionHandler while storing the old handler as a variable inside, so that the class would act as a listener. Then you can call all of the old handler's methods inside of the corresponded methods of the class, and do some checks before that and break if needed.
for CommandHandlers my custom handler would be assigned to IUIX_Cmd.

Having an ActionHandler - assign it to what?

I see Inst has GetHandlerForAction(nActionType) - what would be nActionType (I guess goto, gotor and alike)?


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

Re: Link (gotor/launch) navigation events + a few questions + an AV in Delphi

Post by Sasha - Tracker Dev Team »

Hello žarko,

After creating a class, derived from the IPXC_ActionHandler, you should register it, using the IPXC_Inst::RegisterActionHandler method. To obtain the needed ID, you should use the StrToAtom method and pass PDF Specification Action Type string for example "GoTo" (case sensitive).

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Re: Link (gotor/launch) navigation events + a few questions + an AV in Delphi

Post by zarkogajic »

zarkogajic wrote: Wed Sep 25, 2019 2:12 pm "works on my machine" will not help here :)
Hi Alex,

I see another Delphi user with the same problem (from year before) : viewtopic.php?t=31738

Any chance your Delphi-guy can double check this?

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

Re: Link (gotor/launch) navigation events + a few questions + an AV in Delphi

Post by Sasha - Tracker Dev Team »

Hello žarko,

Can you try doing a try/catch statement around that code - probably this is also some Delphi hresult handling of some sort.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Re: Link (gotor/launch) navigation events + a few questions + an AV in Delphi

Post by zarkogajic »

Alex,

There's no code involved. So nothing to try/catch.

By default (just drop pxv_control on a form) tabs are not activated, so every loaded document will replace the previously loaded document (meaning that at a time one document can be displayed by the Control).

When a document has a link, a user (so no code) clicks the link - the target document is opened (and replaces the "source" document) - at this moment the AV is raised. The target document does get loaded though.

This does not happen when tabs are involved and opening the target document creates a new tab.

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

Re: Link (gotor/launch) navigation events + a few questions + an AV in Delphi  SOLVED

Post by Sasha - Tracker Dev Team »

Hello žarko,

There is always a point on top of the program, where the form itself is being created - there you can use try/catch.
Sadly, we couldn't reproduce this one with the same Delphi version, so for now, I can't tell you more.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Re: Link (gotor/launch) navigation events + a few questions + an AV in Delphi

Post by zarkogajic »

Ok, case closed.

Post Reply