TCoPDFXCview.OnEvent how to work with?

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

Nebulo
User
Posts: 15
Joined: Fri Nov 21, 2008 10:27 pm

TCoPDFXCview.OnEvent how to work with?

Post by Nebulo »

Hi,

I'd like to get keyboard events from TCoPDFXCview.
Please take a look at the small Delphi app attached. There is nothing but assigned OnEvent. This application is crashing at the beginning with 'Access violation error at address...'
I am using Delphi 7.

Am I doing something wrong?
Please advise.

Sincerely
Nebulo
You do not have the required permissions to view the files attached to this post.
Corwin - Tracker Sup
User
Posts: 664
Joined: Tue Nov 14, 2006 12:23 pm

Re: TCoPDFXCview.OnEvent how to work with?

Post by Corwin - Tracker Sup »

Hello Nebulo,

Try to change CoPDFXCview1Event declaration to this one:

Code: Select all

 procedure TForm1.CoPDFXCview1Event(ASender: TObject; Type_: Integer;
  const Name: WideString; const DataIn: OleVariant; out DataOut: OleVariant;
  Flags: Integer);
Also I'd recommend you to take a look at the samples in: <Tracker Software Folder>\PDF-XChange Viewer SDK\Examples\DelphiExamples
HTH.
Nebulo
User
Posts: 15
Joined: Fri Nov 21, 2008 10:27 pm

Re: TCoPDFXCview.OnEvent how to work with?

Post by Nebulo »

It works! Thanks a lot.
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19883
Joined: Mon Jan 12, 2009 8:07 am

Re: TCoPDFXCview.OnEvent how to work with?

Post by Stefan - PDF-XChange »

:)
Nebulo
User
Posts: 15
Joined: Fri Nov 21, 2008 10:27 pm

Re: TCoPDFXCview.OnEvent how to work with?

Post by Nebulo »

I've worked a little with that and it looks that everything is OK if:
1. TCoPDFXCview is created and OnEvent is assigned at design time, so if you want to have full control on what and when is created and released (create and free TCoPDFXCview at runtime), it is a problem.
2. DataIn argument of OnEvent handler is not referred in any way.

If one of these two points is not true, an application is crashing.
For example: I want to react on PXCVA_OnNamedNotify, Global::CheckKey
In this case virtual key code is in DataIn argument (as it is in PDFV_AX.pdf page 271), but when I'm trying to read DataIn (if DataIn = VK_ESCAPE then ...), the application shows 'access violation at address...'

I've found a workaround and I'm using:
"FCoPDFXCview.SetProperty('Notifications.Keyboard.Filter', 'All', PXCVA_Sync)" in FormShow and
"FCoPDFXCview.GetProperty('Notifications.Keyboard.Code', outData, PXCVA_Sync)" in OnEvent handler

but I it is still a little strange behavior, isn't it?

Sincerely
Nebulo
Corwin - Tracker Sup
User
Posts: 664
Joined: Tue Nov 14, 2006 12:23 pm

Re: TCoPDFXCview.OnEvent how to work with?

Post by Corwin - Tracker Sup »

but I it is still a little strange behavior, isn't it?
That's all right with this. In OnEvent code you can also use something like that:

Code: Select all

var
	str:string;
	spKeyboard: IPDFXCsmartp;
	vDataIn,vDataOut:OleVariant;
....

if type_ = PXCVA_OnNamedNotify then
begin
 if Name = 'Notifications.Keyboard' then
 begin
   //
   CoPDFXCview1.DoVerb('Notifications.Keyboard', '.SP', vDataIn, vDataOut, 0);
   spKeyboard:=IDispatch(vDataOut) as IPDFXCsmartp;
   spKeyboard.GetProperty('Msg', vDataOut, 0);
   str:='Key msg = ' + inttostr(vDataOut)+' ';

   spKeyboard.GetProperty('Code', vDataOut, 0);
   str:=str+'Code = ' + inttostr(vDataOut)+' ';

   spKeyboard.GetProperty('RepCnt', vDataOut, 0);
   str:=str+'RepCnt = ' + inttostr(vDataOut)+' ';

   spKeyboard.GetProperty('Flags', vDataOut, 0);
   str:=str+'Flags = ' + inttostr(vDataOut)+' ';

   //spKeyboard.SetProperty('Skip', 1, 0);
   Memo1.Lines.add(str);
 end;
end;