<html><p>Wolfgang,</p><p>I verified that there is a bug related to how Basic handles arrays of Structures.</p><p>I tested against LibreOffice 7.2.2.2 on Fedora Linux as well as Windows 7.1.2.2 and 7.2.4.1 so I filed a bug report:</p><p><a href="https://bugs.documentfoundation.org/show_bug.cgi?id=146082">https://bugs.documentfoundation.org/show_bug.cgi?id=146082</a></p><p>Note that a Structure copies by value, not be reference.</p><p>A work around until the bug is fixed, is to not use a notation such as:</p><p> </p><p>Dim p(1 To 2) As PersonType</p><p>Dim p(1 To 2) As New com.sun.star.awt.Point</p><p> </p><p>Instead, define the array as an Object or Variant and then initialize each entry</p><p> </p><p>p(1) = CreateUnoStruct( "com.sun.star.awt.Point" )</p><p>p(2) = CreateUnoStruct( "com.sun.star.awt.Point" )</p><p> </p><p>Use CreateObject("PersonType") for user defined types.</p><p> </p><p>Developers,</p><p> </p><p>Any suggestions as to where I might find the code where an array is “initialized” or where to look for handling to suggest what might cause the really strange behavior? I have not looked at LibreOffice code or built it for a while now.</p><p> </p><p>Clearly there are differences in how an UNO struct and a user defined structure is created and stored since an array value might show as different depending on whether or not we copy it after access it. And how different solutions vary depending on the type after passed as an argument.</p><p> </p><p>For those who are interested but too lazy to look up the bug referenced above:</p><p> </p><p>This bug was originally noted with a user defined type so I wrote a test using a built-in UNO Struct com.sun.star.awt.Point</p><p> </p><p>Test using User type “PersonType”</p><p> </p><p>Type PersonType</p><p>FirstName As String</p><p>LastName As String</p><p>End Type</p><p> </p><p>Sub PrintPersons(s, x)</p><p>Print "Expect (" & s & ") found (" & x.FirstName & " " & x.LastName & ")"</p><p>End Sub</p><p> </p><p>Sub PrintPoint(s, x)</p><p>Print "Expect " & s & " Found (" & x.X & ", " & x.Y & ")"</p><p>End Sub</p><p> </p><p>This is the original disturbing code. Attempting to copy an element from the array causes problems. The same when trying to assign back into to the array.</p><p> </p><p> </p><p>Sub otherExampleCreateNewType</p><p>REM Producing very strange errors.</p><p>REM Inspect the two array elements and h at the same time</p><p>REM down to the inside variables while executing lines 19 through 21 stepwise.</p><p> </p><p>Dim Person(1 To 2) As PersonType</p><p>Person(1).FirstName = "Andrew"</p><p>Person(1).LastName = "Pitonyak"</p><p>Person(2).FirstName = "Funny"</p><p>Person(2).LastName = "Lupp"</p><p> </p><p>PrintPersons("Andrew", Person(1)) ' Andrew (correct)</p><p>PrintPersons("Funny", Person(2)) ' Funny (correct)</p><p> </p><p>Dim h As PersonType</p><p>h = Person(1)</p><p>Person(1) = Person(2)</p><p>Person(2) = h</p><p>PrintPersons("Funny", Person(1)) ' Andrew (wrong)</p><p>PrintPersons("Andrew", Person(2)) ' Funny (wrong)</p><p> </p><p>REM Now look at the prints, and frown.</p><p>Dim h1 As PersonType, h2 As PersonType</p><p>h1 = Person(1)</p><p>h2 = Person(2)</p><p>PrintPersons("Funny", h1) ' Funny (correct)</p><p>PrintPersons("Andrew", h2) ' Funny (wrong)</p><p> </p><p>End Sub</p><p> </p><p>Next I run this using a built-in UNO type and have exactly the same incorrect behaviors</p><p>Sub otherExampleCreateAWTPoint</p><p> </p><p>Dim p(1 To 2) As New com.sun.star.awt.Point</p><p>p(1).X = 1</p><p>p(1).Y = 2</p><p>p(2).X = 3</p><p>p(2).Y = 4</p><p> </p><p>PrintPoint("(1, 2)", p(1)) ' Correct</p><p>PrintPoint("(3, 4)", p(2)) ' Correct</p><p> </p><p>Dim h As New com.sun.star.awt.Point</p><p>h = p(1)</p><p>p(1) = p(2)</p><p>p(2) = h</p><p>PrintPoint("(3, 4)", p(1)) ' wrong</p><p>PrintPoint("(1, 2)", p(2)) ' wrong</p><p> </p><p>REM Now look at the prints, and frown.</p><p>Dim h1 As New com.sun.star.awt.Point, h2 As New com.sun.star.awt.Point</p><p>h1 = p(1)</p><p>h2 = p(2)</p><p>PrintPoint("(3, 4)", h1) ' Correct</p><p>PrintPoint("(1, 2)", h2) ' Wrong</p><p> </p><p>End Sub</p><p> </p><p>I then changed how the array is declared as shown below and this fixed the problematic</p><p> </p><p>Dim p(1 To 2) As Object</p><p>p(1) = CreateUnoStruct( "com.sun.star.awt.Point" )</p><p>p(2) = CreateUnoStruct( "com.sun.star.awt.Point" )</p><p> </p><p>Doing the same for the PersonType also causes it to work as expected:</p><p> </p><p>Dim Person(1 To 2) As Object</p><p>Person(1) = CreateObject("PersonType")</p><p>Person(2) = CreateObject("PersonType")</p><p> </p><p>It gets worse. If I modify the subroutine to always make a copy of the object and then use the object that is passed to the subroutine, then suddenly the first program works for points, but the same fix does not work when done for PersonType.</p><p> </p><p>Sub PrintPoint(s, y)</p><p>Dim x</p><p>x = y</p><p>Print "Expect " & s & " Found (" & x.X & ", " & x.Y & ")"</p><p>End Sub</p><p> </p><p>Clearly something is wrong / inconsistent.</p><p> </p><p> </p><p> </p></html>