I wrote a macro that inserts a TextGraphicObject in a text document. Another macro is assigned to the OnSelect event of this object. To do the assignation I get the object's events and replaceByName the OnSelect event. It works successfully. Later, I want to change the macro assigned to this event. So again I want to replaceByName the event, but it does nothing: the previous macro stays assigned to the event. Neither can I "erase" the event by replacing it with a "None" type event. Here is some sample code : Sub test Graph = ThisComponent.createInstance("com.sun.star.text.TextGraphicObject") ' on a side note : assigning events before inserting the TextGraphicObject crashes LibreOffice ThisComponent.getText().insertTextContent(ThisComponent.getText().getStart(), Graph, false) ' sets the OnSelect event Dim Ev1(1) as new com.sun.star.beans.PropertyValue Ev1(0).Name = "EventType" Ev1(0).Value = "Script" Ev1(1).Name = "Script" Ev1(1).Value = "vnd.sun.star.script:Standard.Module1.sub1?language=Basic&location=document" Graph.getEvents().replaceByName("OnSelect", Ev1) ' the msgbox correctly displays the sub1 target Good = Graph.getEvents().getByName("OnSelect") msgbox Good(1).Value ' now replace the OnSelect event Dim Ev2(1) as new com.sun.star.beans.PropertyValue Ev2(0).Name = "EventType" Ev2(0).Value = "Script" Ev2(1).Name = "Script" Ev2(1).Value = "vnd.sun.star.script:Standard.Module1.sub2?language=Basic&location=document" Graph.getEvents().replaceByName("OnSelect", Ev2) ' the target is still sub1, where it should now be sub2 Bad = Graph.getEvents().getByName("OnSelect") msgbox Bad(1).Value End Sub I may not be using these API correctly, but doing the same with other types of objects (like reassigning the OnLoad event of ThisComponent) works as I intend. Had the same behaviour on LO6.4.6.2 on MacOS and Windows 10.
Marking as new as I see the same result as described in your macro comments, and as it seems unexpected, in a recent master build: Version: 7.6.0.0.alpha0+ (X86_64) / LibreOffice Community Build ID: b10417eb1e5a4a6959e7fc1cdd9819e5b09d39a4 CPU threads: 8; OS: Linux 5.15; UI render: default; VCL: gtk3 Locale: en-AU (en_AU.UTF-8); UI: en-US Calc: threaded As well as LO 6.0: Version: 6.0.0.3 Build ID: 64a0f66915f38c6217de274f0aa8e15618924765 CPU threads: 8; OS: Linux 5.15; UI render: default; VCL: gtk2; Locale: en-AU (en_AU.UTF-8); Calc: group But the value does update properly in OOo 3.3, so this is a regression.
I gave a try with https://gerrit.libreoffice.org/c/core/+/156651
Julien Nabet committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/1806691c91b45b3ee5a52efc585930c41c705127 tdf#141123: impossible to replace an event after it has been set It will be available in 24.2.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.