Bug 141123 - Impossible to replace a TextGraphicObject's event after it has been set
Summary: Impossible to replace a TextGraphicObject's event after it has been set
Status: UNCONFIRMED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
6.4.6.2 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: QA:needsComment
Keywords:
Depends on:
Blocks: Macro
  Show dependency treegraph
 
Reported: 2021-03-20 08:18 UTC by rsaintier
Modified: 2022-04-10 15:11 UTC (History)
0 users

See Also:
Crash report or crash signature:
Regression By:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description rsaintier 2021-03-20 08:18:27 UTC
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.