<html>
    <head>
      <base href="https://bugs.documentfoundation.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_UNCONFIRMED "
   title="UNCONFIRMED - Impossible to replace a TextGraphicObject's event after it has been set"
   href="https://bugs.documentfoundation.org/show_bug.cgi?id=141123">141123</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Impossible to replace a TextGraphicObject's event after it has been set
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>LibreOffice
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>6.4.6.2 release
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>UNCONFIRMED
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>BASIC
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>libreoffice-bugs@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>rsaintier@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>