Forum > Windows
LibreOffice events listener
chris_laz:
Hi all,
I am attempting to port a Delphi app which runs LibreOffice by automation and listens for document save and close events, but I can't quite get it to work in Lazarus.
I am using Lazarus 3.6/FPC 3.22 on Windows 10, with LibreOffice 7.4 (all 64bit).
The Delphi code implements an event listener for LO by implementing a TAutoObject with an IConnectionPointContainer, but I can't get this to work in Lazarus, as FPC does not appear to include any implementations of the IConnectionPointContainer interface (Delphi has a TConnectionPoints class).
I have tried reimplementing this, but with no success so far.
I can run LO and open a doc in Calc successfully, but my event listener does nothing (but doesn't crash).
Has anyone managed to implement an event listener for LO in Lazarus?
I can share the code I've tried so far if that's any help, or if there is a pre-built event listener somewhere, that would also be a great help!
Thanks
cdbc:
Hi
Yup, let's see the code you have so far... ;)
Crystal balls are hard to program with :D
Regards Benny
egsuh:
Yes, I'd like to see your codes as well... (to learn more... ^^)
chris_laz:
OK here goes -
In main unit
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var libreMgr, libreDsk, libreDoc: OleVariant; libreEvents: ILibreOfficeEvents; ... libreMgr := CreateOleObject('com.sun.star.ServiceManager'); libreDsk := LibreMgr.createInstance('com.sun.star.frame.Desktop'); libreDoc := libreDsk.loadComponentFromFile(filename etc...); libreEvents := TLibreOfficeEvents.Create; libreEvents.OnPrepareUnload := event handler method libreDoc.addEventListener(libreEvents);
See attached units
LibreOfficeEventListener - implementation of TLibreOfficeEvents with internal ILibreOfficeEvents declaration
LibreOfficeEventListener_TLB - imported LO type library, declaration of LO ILibreOfficeEventListener interface
ActiveXConnectionPoints - custom implementation of IConnectionPointContainer
ComServNoRegisterLaz - override default FPC TComServer implementation to remove registry updates
I am not sure where my original Delphi implementation came from (back in 2011), I must have found some hints online, as I am pretty sure I did not work this all out for myself.
The LO type library must be loaded as a resource in the exe, but does not need to be added to the registry. This allows the app to run without admin privileges, hence the overrides of the default TComServer and TAutoObjectFactory to remove registry updates.
This all compiles OK in Lazarus, but the events do not fire at all after the LO document is opened and the event listener is added, and there are no runtime errors.
chris_laz:
No suggestions?
Has anyone else managed to hook LibreOffice automation events in a Lazarus app?
Navigation
[0] Message Index
[#] Next page