[Solved] OOo 3.0RC2: addEventListener not working

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
mobi-doc
Posts: 59
Joined: Wed Nov 21, 2007 11:29 am
Location: Greece

[Solved] OOo 3.0RC2: addEventListener not working

Post by mobi-doc »

The following code is on a Base form and its purpose is to open another Base form of the same ODB file and set a closing event listener:

Code: Select all

1 Sub openForm
2 Dim form
3 Dim prop(2) as New com.sun.star.beans.PropertyValue
4	prop(0).Name="ActiveConnection"
5	prop(0).Value=ThisComponent.Parent.DataSource.getConnection("","")
6	prop(1).Name="OpenMode"
7	prop(1).Value="open"
8	prop(2).Name="MacroExecutionMode"
9	prop(2).Value=com.sun.star.document.MacroExecMode.ALWAYS_EXECUTE_NO_WARN
10	form=ThisComponent.Parent.FormDocuments.loadComponentFromURL("someForm","_default",com.sun.star.frame.FrameSearchFlag.CREATE,prop())
11	form.addEventListener(CreateUnoListener("customListener_","com.sun.star.lang.XEventListener"))
12 End Sub
The code works in OOo 2.4.1 under XP and Ubuntu 8.04.

But with OOo 3.0RC2 the following error appears in line 11:

BASIC runtime error.
An exception occurred
Type: com.sun.star.lang.IllegalArgumentException
Message: cannot coerce argument type during corereflection call!

Anyone knows what changed in UNO API to cause this error?

Thanks.
Last edited by Hagar Delest on Wed Sep 24, 2008 1:21 pm, edited 1 time in total.
Reason: tagged the thread as Solved.
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: OOo 3.0RC2: addEventListener not working

Post by Villeroy »

Since version3 databases have their own macro container and component context, so all the voodoo to disable macro security and references to ThisComponent.Parent are obsolete. This seems to be the only important change in Base.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
mobi-doc
Posts: 59
Joined: Wed Nov 21, 2007 11:29 am
Location: Greece

Re: OOo 3.0RC2: addEventListener not working

Post by mobi-doc »

Can you be more specific?
I thought that this change is postponed for 3.1, as long as I can not have a Base file with its own macros yet for 3.0RC1. I have already had problems with changes in User Defined Document Properties API. But this is worst.
Do you know any link that lists the details of UNO API changes in Base 3.0?

Thank you very much.
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: OOo 3.0RC2: addEventListener not working

Post by Villeroy »

mobi-doc wrote:Can you be more specific?
I thought that this change is postponed for 3.1, as long as I can not have a Base file with its own macros yet for 3.0RC1. I have already had problems with changes in User Defined Document Properties API. But this is worst.
Do you know any link that lists the details of UNO API changes in Base 3.0?

Thank you very much.
I read this several times in the mail lists. You are right. They postponed this important feature. Base seems to be even more dead than I thought.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
mobi-doc
Posts: 59
Joined: Wed Nov 21, 2007 11:29 am
Location: Greece

Re: OOo 3.0RC2: addEventListener not working

Post by mobi-doc »

A test.odb file has been uploaded. It runs ok with OOo 2.4.x but it gives error with OOo 3.0RC2.
Attachments
test.odb
test.odb: It runs ok with OOo 2.4.x but it gives error with OOo 3.0RC2.
(18.4 KiB) Downloaded 174 times
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: OOo 3.0RC2: addEventListener not working

Post by hanya »

Hi,

the error message is caused by the calling addEventListener method of com.sun.star.document.XEventBroadcaster interface. Try linke the following to call the correct one:

Code: Select all

  l = CreateUnoListener("customListener_","com.sun.star.lang.XEventListener")
  form.com_sun_star_lang_XComponent_addEventListener(l)
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
mobi-doc
Posts: 59
Joined: Wed Nov 21, 2007 11:29 am
Location: Greece

Re: OOo 3.0RC2: addEventListener not working

Post by mobi-doc »

It worked! Thanks.

But for my quriosity, can you explain what is this peculiar code in the last line?

What is the difference with the code I used to use and what makes it work under 3.0RC2.

Thanks again.
mobi-doc
Posts: 59
Joined: Wed Nov 21, 2007 11:29 am
Location: Greece

Re: [Solved] OOo 3.0RC2: addEventListener not working

Post by mobi-doc »

After testing with some code I found out that a lot of things changed with listeners that lead to unpredicted behaviour and errors. Please some developer inform us about the changes, or perhaps its bugs that cause all these.

For now I can not run an application, I'm developing for a year and a half, consisting of several forms, under 3RC2.

Questions:

Why someForm.addEventListener do not work in 3.0 ?

Why the need for someForm.com_sun_star_lang_XComponent_addEventListener in order to work in 3.0 ?

Or why the need for someForm.CurrentController.addEventListener in order to work in 3.0 ?

Why all of the above have unpredicted behaviour (sometimes work, sometimes they don't) if someForm is
ThisComponent or ThisComponent.CurrentController?

I'm terrified. OOo 3.0 is around the corner and a lot of my code is going to break without any clue about how to fix it.

PLEASE HELP!
Thanks.
User avatar
Hagar Delest
Moderator
Posts: 32658
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: [Solved] OOo 3.0RC2: addEventListener not working

Post by Hagar Delest »

mobi-doc wrote:Please some developer inform us about the changes
We're are just users here. No developer at all.
To contact them, the only way is to file a bug report: [Tutorial] Reporting bugs or suggestions.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: [Solved] OOo 3.0RC2: addEventListener not working

Post by hanya »

mobi-doc wrote: Why someForm.addEventListener do not work in 3.0 ?

Why the need for someForm.com_sun_star_lang_XComponent_addEventListener in order to work in 3.0 ?

Or why the need for someForm.CurrentController.addEventListener in order to work in 3.0 ?

Why all of the above have unpredicted behaviour (sometimes work, sometimes they don't) if someForm is
ThisComponent or ThisComponent.CurrentController?
The document object of writer supports com.sun.star.lang.XComponent, com.sun.star.document.XEventBroadcaster and so on.

Defined in com.sun.star.document.XEventBroadcaster:

Code: Select all

void addEventListener( [in] com.sun.star.document.XEventListener Listener )
Defined in com.sun.star.lang.XComponent:

Code: Select all

void addEventListener( [in] com.sun.star.lang.XEventListener xListener )
They have the same name "addEventListener" and the program does not know which method is called by the user. I think the method found first in the object is called.

The peculiar com_sun_star_lang_XComponent_addEventListener kind of method call is well (?) known by the user of the OOo Basic experience to use XEventBroadcaster interfaces. I think the problem is caused Basic does not allow to define methods with the same name and different arguments.
See:
http://wiki.services.openoffice.org/wik ... ent_Events

In this case, I think you needed to call the method with quolified name.
I'm terrified. OOo 3.0 is around the corner and a lot of my code is going to break without any clue about how to fix it.
The object of the document is changed on 3.0 but the problem is not new one. But I wonder the order of the calling methods is changed...
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
Post Reply