[Libreoffice-bugs] [Bug 132064] New: "With" statement likely evaluates its argument on each unqualified member access
bugzilla-daemon at bugs.documentfoundation.org
bugzilla-daemon at bugs.documentfoundation.org
Sun Apr 12 12:27:29 UTC 2020
https://bugs.documentfoundation.org/show_bug.cgi?id=132064
Bug ID: 132064
Summary: "With" statement likely evaluates its argument on each
unqualified member access
Product: LibreOffice
Version: 6.4.2.2 release
Hardware: All
OS: All
Status: UNCONFIRMED
Severity: normal
Priority: medium
Component: BASIC
Assignee: libreoffice-bugs at lists.freedesktop.org
Reporter: mikekaganski at hotmail.com
Look at this BASIC code:
> 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
This code will show "True", irrespective of previous setting value (which means
it works as expected).
Now modify that like this:
> 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
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":
> Use With and End With if you have several properties or methods for a single object.
VBA help [2] also says about that:
> Executes a series of statements on a single object or a user-defined type.
VB help [3] goes even further:
> objectExpression Required. An expression that evaluates to an object. The expression may be arbitrarily complex and is evaluated only once.
So the implementation of With looks inconsistent, unexpected, inefficient (in
the best case) and wrong.
[1] https://help.libreoffice.org/6.4/en-US/text/sbasic/shared/03090411.html
[2]
https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/with-statement
[3]
https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/with-end-with-statement
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
--
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/20200412/87d30374/attachment-0001.htm>
More information about the Libreoffice-bugs
mailing list