[Libreoffice-bugs] [Bug 130888] New: Basic is Faulty in creating / deleting User Defined Properties

bugzilla-daemon at bugs.documentfoundation.org bugzilla-daemon at bugs.documentfoundation.org
Sun Feb 23 21:27:03 UTC 2020


https://bugs.documentfoundation.org/show_bug.cgi?id=130888

            Bug ID: 130888
           Summary: Basic is Faulty in creating / deleting User Defined
                    Properties
           Product: LibreOffice
           Version: 6.3.4.2 release
          Hardware: x86 (IA32)
                OS: Windows (All)
            Status: UNCONFIRMED
          Severity: normal
          Priority: medium
         Component: BASIC
          Assignee: libreoffice-bugs at lists.freedesktop.org
          Reporter: atemple at rogers.com

I created the BASIC example below that illustrates and replicates the bug. You
can copy this code into any Writer document's Basic IDE, compile it, then run
the macros as I'll outline.

The problem is that I can create a User Defined Property from a BASIC macro,
and I can then access it, and print its current value. But if I try to use
another macro to delete the UDP, I get a run-time error. (It gets even weirder
than this.) You can reproduce this bug as follows:

First of all, you can run BugTest1() to create the UDP, "UDP1" with value:
"This is a User Defined Property!"

Next, run BugTest2(). It will simply access the new UDP and print its current
value in a MsgBox(). So far, so good. Now comes the bizarre behavior.

Now run BugTest3() which simply tries to delete the newly created UDP. (By
DeleteUDProperty("UDP1")) It results in a run-time error.

There is more odd behavior to explain here. To begin with, after you've run
BugTest1() to create the UDP, then go to File --> Properties --> Custom
Properties, you won't find the newly created UDP listed there. BUT -- when you
run BugTest2() it can somehow access it, and display its value. BugTest3() as
shown cannot delete it. Now, if you've run the three tests, had the run-time
error, and now save the file AND CLOSE IT, then reopen it, then look at the
UDPs (File --> Properties --> Custom Properties) you'll see that the UDP we
created with BugTest1() has suddenly shown up in the list. If you NOW run
ButTest3(), you'll see that the UDP can now be successfully deleted by the
macro without generating any run-time error.

Again, you can use BugTest1() to create the UDP, then click on the Save icon to
save the file, and still the UDP will not be listed in the Custom Properties.
You must actually close the document, and then reopen it to get it listed.

I can also confirm that this bug is present in OpenOffice 4.1.6 and behaves
exactly the same, so this was almost certainly something that Libre inherited
when it was forked. (I also upgraded to Libre 6.3.4.2 before filing this
report, just to make sure it still persists.)

Being a long-time, amateur programmer, the most likely explanation that I can
think of for this behavior is that the UDPs appear to be read from the document
into some temporary store that is accessed by all the macro functions
(hasPropertyByName(), addProperty(), setPropertyValue() and
getPropertyValue()). Whatever modifications occur here seem to be held back and
are only written to the document when it is closed. On the other hand,
removeProperty() seems to access a different store of the UDPs, possibly the
document itself, so it can't delete a UDP that the other functions create until
AFTER the document has actually been closed and reopened.

I hope this is a clear-enough explanation of what's happening. Thanks.



'
-------------------------------------------------------------------------------------------------


Sub CreateUDProperty(UDProp As String, Value As String)

  DocUDProps = ThisComponent.DocumentProperties.UserDefinedProperties

  If DocUDProps.getPropertySetInfo().hasPropertyByName(UDProp) = false Then
     DocUDProps.addProperty(UDProp, 0, Value)
  Else
     DocUDProps.setPropertyValue(UDProp, Value)
  End If

End Sub



Sub DeleteUDProperty(UDProp As String)

  DocUDProps = ThisComponent.DocumentProperties.UserDefinedProperties

  If DocUDProps.getPropertySetInfo().hasPropertyByName(UDProp) = True Then
     MsgBox("About to delete " & UDProp)
     MsgBox("Current value of " & UDProp & " is " &
DocUDProps.getPropertyValue(UDProp))
     DocUDProps.removeProperty(UDProp)
  End If

End Sub


Sub BugTest1()

  CreateUDProperty("UDP1", "This is a User Defined Property!")
  MsgBox("Created UDP1.")

End Sub


Sub BugTest2()

  DocUDProps = ThisComponent.DocumentProperties.UserDefinedProperties

  If DocUDProps.getPropertySetInfo().hasPropertyByName("UDP1") Then
     MsgBox("Here is UDP1: " & DocUDProps.getPropertyValue("UDP1")
  Else
     MsgBox("Can't find UDP1!")
  End If

End Sub


Sub BugTest3()

  DeleteUDProperty("UDP1")

End Sub

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/libreoffice-bugs/attachments/20200223/951fd746/attachment.htm>


More information about the Libreoffice-bugs mailing list