Bug 130307 - Support For Each loop for objects exposing XIndexAccess
Summary: Support For Each loop for objects exposing XIndexAccess
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium enhancement
Assignee: Andreas Heinisch
URL:
Whiteboard: target:7.3.0
Keywords:
Depends on:
Blocks:
 
Reported: 2020-01-31 08:38 UTC by Mike Kaganski
Modified: 2021-10-28 09:24 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Kaganski 2020-01-31 08:38:01 UTC
Currently it's impossible to iterate over objects contained in UNO objects exposing XIndexAccess

E.g., execute this macro in a writer document:

Sub bookmks
oDoc=thisComponent
bookmarks = oDoc.Bookmarks
For Each bookmark in bookmarks()
    print bookmark.Name
Next bookmark
End Sub

This fails on "For Each" with "Inadmissible value or data type. Data type mismatch." error. One needs to use index access:

Sub bookmks1
oDoc=thisComponent
bookmarks = oDoc.Bookmarks
For i = 0 to bookmarks.Count-1
    print bookmarks.getByIndex(i).Name
Next i
End Sub

I suppose that having the syntactic sugar for objects exposing XIndexAccess would be nice.
Comment 1 Mike Kaganski 2020-01-31 08:49:27 UTC
(In reply to Mike Kaganski from comment #0)
> Currently it's impossible to iterate over objects contained in UNO objects
> exposing XIndexAccess

Of course, "impossible to iterate over objects using For Each" was meant.
Comment 2 Tushar Kumar Rai 2021-03-11 14:34:37 UTC
(In reply to Mike Kaganski from comment #0)

Hello i want to work on this enhancement.

Please provide some pointers like at which file in source code we need to make changes.

Thanks.
Comment 3 himajin100000 2021-10-03 16:40:35 UTC
https://opengrok.libreoffice.org/xref/core/basic/source/runtime/runtime.cxx?r=adb38e36#1201

(away from this bug itself, but it seems For-Each on COM object fails)
Comment 4 Commit Notification 2021-10-12 19:11:49 UTC
Andreas Heinisch committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/5c502a100476c6b57a1a9f4305195c7e2d5d5608

tdf#130307 - Support for each loop for objects exposing XIndexAccess

It will be available in 7.3.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 5 Andreas Heinisch 2021-10-12 19:29:12 UTC
You may open a new bug report for the COM objects himajin100000?
Comment 6 himajin100000 2021-10-19 05:47:39 UTC
in addition to tdf#118241, 

a user is asking about the returned value of VBScript.RegExp's Execute method.
https://ask.libreoffice.org/t/calc-vba-vbscript-regexp/52106