OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

[Solution] XEventListener with Ole Bridge and Delphi

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
havardo
General User
General User


Joined: 21 Jun 2007
Posts: 11

PostPosted: Thu Jun 28, 2007 6:04 am    Post subject: [Solution] XEventListener with Ole Bridge and Delphi Reply with quote

Hi,
I’ve seen several postings about this problem and have found one solution. The solution I’ve ended up with is far from perfect, but as time is of short supply at the moment, I have decided to stop tinkering.

The solution is based on the VB example implementing the XEventListener found in the Developer Guide (Page 189, May 2007 version).
The key is to implement the listener in an “Active X” dll in the same manner as they suggest for VB. I tried to get it work with a TObjectDispatch and a TInterfacedObject descendent, but it looks as if the Ole Bridge requires you to implement the IDispatch.GetTypeInfo method properly. This is done automagicly if your parent class is TAutoobject. Hence, if you build and Automation Object in an Active X dll, this is ready out of the box.
Second problem is that I have not managed to implement any other listener than the basic com.sun.star.lang.XEventListener. This is sufficient for my needs. I have tried to implement the XCloseListener without success. I suspect that I did not manage to declare the queryClosing method properly.
Create an ActiveX dll and add an AutomationObject with the default options to the project. Check “yes” for “Generate event support code”.
Your default interface should look like this:
Code:
function Bridge_ImplementedInterfaces: OleVariant [propget, dispid $000000C9]; safecall;
procedure disposing(ASource: OleVariant) [dispid $000000CA]; safecall;

Add an event to your Automation object. Mine looks like this..
Code:
function OnOoNotivyEvent(AEventname: WideString): HResult [dispid $000000C9]; stdcall;

Implement the DLL..
Code:
function TMyEventlistener.Get_Bridge_ImplementedInterfaces: OleVariant;
begin
  result := VarArrayOf(['com.sun.star.lang.XEventListener']);
end;
procedure TMyEventlistener.disposing(ASource: OleVariant);
begin
  if assigned(FEvents) then
    FEvents.OnOoNotivyEvent('disposing');
end;

On the client, you need to implement a COM Eventsink. I recommend you download the EventSinkImp, made by Binh Ly from http://www.techvanguards.com. And import your ActiveX Dll.

Finally, you need to hook up everything on the client.
I assume here that you already have started up the Ole Bridge manager and desktop and that you have a reference to the document.
Code:
FLocalEventSink := TMyBinhLyGeneratedEventsink.Create(nil);
//Plug in eventhandler on my form
FLocalEventSink.OnOoNotivyEvent := self.OnOoDocumentEvent;
//Create instance of Active X Automation Object
FOleEventListener := CreateOleObject(MyOoUtils.MyEventListener');
// Connect eventsink to Automation Object
FLocalEventSink.Connect(FOleEventListener);
//Connect Automation Object to Open Office Document
FActiveDocument.AddEventListener(FOleEventListener);

To summarize, your cake should look a bit like this:
    First layer is the Oo Writer.
    Second layer is the Open Office Ole Automation Bridge.
    Third layer is our own custom Automation Object implementing the XEventListener residing in a ActiveX dll
    Forth layer is our EventSink on the client
    Fifth layer is our Form.


Bon appetit.
Any comments/suggestions are very welcome.
Havard
Back to top
View user's profile Send private message
rufus
General User
General User


Joined: 18 May 2007
Posts: 17
Location: Russia, Moscow

PostPosted: Fri Dec 14, 2007 5:43 am    Post subject: Reply with quote

Hi, havardo!

Your example is very actual for me, because now I have the same task. But I have some problems with creating an ActiveX dll that you recomended.

Could you describe this point more detail or attach your workable dll here, please?

Thank you.
_________________
Windows XP Professional sp2 + OO 2.2.0
Back to top
View user's profile Send private message
smbrant
General User
General User


Joined: 19 Nov 2003
Posts: 13
Location: Belo Horizonte, Brazil

PostPosted: Wed Apr 22, 2009 5:32 pm    Post subject: Capturing ooo events with Delphi - a complete example Reply with quote

Hi rufus,

After trying various different ways, I discovered how to do it, the easy way.

I published the code at http://github.com/smbrant/oooeventsdelphi

It was created with the following script:
- Create a normal delphi application (code saved as oooEvents.dpr and oooEvents1.pas)
- Add an ActiveX automation object to the project (oooEvents_TLB.pas e oooEvents2.pas)
(I used the CoClass Name 'TListener'
and checked the option 'Generate Event support code'.
You can do this using the menu File/New/Other/ActiveX/Automation Object)
- Add the methods 'disposing' and 'notifyEvent' to the default interface IListener
- Insert code to treat events in the notifyEvent method
- Register the event listener to ooo using the method addListener (in
the ooo object of interest, normally the document, see code associated to the button)
- Remember to register the automation object in Windows with
oooListener /regserver

Use:
- Open a document in ooo
- Run this program and click in the button 'Connect to current document'
- Make changes to the ooo document and see the events being captured.

[]s
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group