<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 - "With" statement likely evaluates its argument on each unqualified member access"
   href="https://bugs.documentfoundation.org/show_bug.cgi?id=132064">132064</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>"With" statement likely evaluates its argument on each unqualified member access
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>6.4.2.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>mikekaganski@hotmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Look at this BASIC code:

<span class="quote">> sub TestRootAccess1
>   GlobalScope.BasicLibraries.LoadLibrary("Tools")
>   Dim KeyWriter As Object
>   KeyWriter = GetRegistryKeyContent("org.openoffice.Office.Calc/Input", True)
>   KeyWriter.setPropertyValue("ExpandReference", True)
>   KeyWriter.commitChanges()
>   ' Use *different* object to read the setting
>   MsgBox GetRegistryKeyContent("org.openoffice.Office.Calc/Input").getByName("ExpandReference")
> end sub</span >

This code will show "True", irrespective of previous setting value (which means
it works as expected).

Now modify that like this:

<span class="quote">> sub TestRootAccess2
>   GlobalScope.BasicLibraries.LoadLibrary("Tools")
>   With GetRegistryKeyContent("org.openoffice.Office.Calc/Input", True)
>     .setPropertyValue("ExpandReference", False)
>     .commitChanges()
>   End With
>   ' Use *different* object to read the setting
>   MsgBox GetRegistryKeyContent("org.openoffice.Office.Calc/Input").getByName("ExpandReference")
> end sub</span >

Now this code will not actually change the setting; e.g., if TestRootAccess2
run after the previous TestRootAccess1, the result of TestRootAccess2 will be
True, not the expected False.

The problem seems to be that the With statement does not evaluate its argument
(GetRegistryKeyContent("org.openoffice.Office.Calc/Input", True)) at entry to
use it later at each member access, but evaluates it each time anew when it
accesses the members of the object using unqualified ".member" syntax. That
means that commitChanges() is executed for a different object than
setPropertyValue(), and the changes are not committed.

The help for With statement [1] mentions "single object":

<span class="quote">> Use With and End With if you have several properties or methods for a single object.</span >

VBA help [2] also says about that:

<span class="quote">> Executes a series of statements on a single object or a user-defined type.</span >

VB help [3] goes even further:

<span class="quote">> objectExpression Required. An expression that evaluates to an object. The expression may be arbitrarily complex and is evaluated only once.</span >

So the implementation of With looks inconsistent, unexpected, inefficient (in
the best case) and wrong.

[1] <a href="https://help.libreoffice.org/6.4/en-US/text/sbasic/shared/03090411.html">https://help.libreoffice.org/6.4/en-US/text/sbasic/shared/03090411.html</a>
[2]
<a href="https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/with-statement">https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/with-statement</a>
[3]
<a href="https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/with-end-with-statement">https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/with-end-with-statement</a>

Tested with Version: 6.4.3.1 (x64)
Build ID: 4d2b2b47cca498fed6abf712a36d0788901091eb
CPU threads: 12; OS: Windows 10.0 Build 18363; UI render: default; VCL: win; 
Locale: en-US (ru_RU); UI-Language: en-US
Calc: threaded</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>