OnEvent Example in Delphi

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

jeffp
User
Posts: 923
Joined: Wed Sep 30, 2009 6:53 pm

OnEvent Example in Delphi

Post by jeffp »

Is there anyway I could get a simple in example in Delphi on how to hook up Events in the ActiveX Viewer.

Here's what I tried to do but I get an AV when the controls gets created.

Code: Select all

procedure TPDFViewerAX.DoOnEvent(ASender: TObject; Type_: Integer;
  const Name: WideString; DataIn: OleVariant; out DataOut: OleVariant;
  Flags: Integer);
begin
  //Monitor events
end;

constructor TPDFViewerAX.CreateEx(AParent: TWinControl);
begin
  inherited Create;
  FPDF := TCoPDFXCview.Create(AParent);
  FPDF.Parent := AParent; //Critical
  FPDF.Align := alClient;
 
  FPDF.OnEvent := DoOnEvent;
end;


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

Re: OnEvent Example in Delphi

Post by Corwin - Tracker Sup »

First select Viewer AX component on Form. Then in "Object Inspector" window go to "events" section and double click in "OnEvent" field - this will create the code to handle events from Viewer.
Also you can find example of how to handle events in the following samples (they all come with the Viewer AX SDK): "Full demo", "Mouse Events", "View".

HTH.
jeffp
User
Posts: 923
Joined: Wed Sep 30, 2009 6:53 pm

Re: OnEvent Example in Delphi

Post by jeffp »

As was indicated in my sample code, I like to create the control from code and then hook up the event from code also.

As such, I see the issue now in what I was trying to do. There is a problem with the definition of the TCoPDFXCviewOnEvent type in your PDFXCviewAxLib_TLB file. It is missing a "const" before the DataIn parameter. It should look like this:

Code: Select all

TCoPDFXCviewOnEvent = procedure(ASender: TObject; 
  Type_: Integer; 
  const Name: WideString; 
  const DataIn: OleVariant; 
  out DataOut: OleVariant; 
  Flags: Integer) of object;
Once I made that change, the event compiles and works correctly now.

Also, it appears the the definition for the _IPDFXCviewEvents interface is missing the "const" as well. However, I don't know much about interfaces so I didn't mess with this one. It seems to compile and work without it in the interface.

You may want to look into this for the next release to make sure the TLB file gets generated correctly.
Corwin - Tracker Sup
User
Posts: 664
Joined: Tue Nov 14, 2006 12:23 pm

Re: OnEvent Example in Delphi

Post by Corwin - Tracker Sup »

I’m glad that you find solution for this problem. I’m not sure how to get Delphi see DataIn as const parameter, but we will try to do something with that.

Thanks.