Issue 91220 - patch: allow string accessors to Basic array variables which represent an UNO object
Summary: patch: allow string accessors to Basic array variables which represent an UNO...
Status: CLOSED WONT_FIX
Alias: None
Product: App Dev
Classification: Unclassified
Component: scripting (show other issues)
Version: 3.3.0 or older (OOo)
Hardware: All All
: P3 Trivial
Target Milestone: ---
Assignee: ab
QA Contact: Unknown
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-06-30 21:15 UTC by Frank Schönheit
Modified: 2013-02-24 21:00 UTC (History)
1 user (show)

See Also:
Issue Type: PATCH
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments
patch (7.15 KB, patch)
2008-06-30 21:16 UTC, Frank Schönheit
no flags Details | Diff
patch with -b, for better readability of what is done (4.79 KB, patch)
2008-06-30 21:21 UTC, Frank Schönheit
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this issue.
Description Frank Schönheit 2008-06-30 21:15:10 UTC
In Basic, if a given variable contains a UNO object supporting the XIndexAccess
interface, it is possible to write something like

  element = container( index )

where "container" is the UNO object supporting XIndexAccess, "index" an integer
value, and "element" the element which is to be retrieved.

It would be nice (and consistent to other scripting languages of competing
products :) to also have a *name access* to UNO containers. That is, if an
object supports XNameAccess, then the following should also be possible:
  element = container( "elementName" )

Currently, this doesn't work, instead the "elementName" is interpreted as
integer value, being 0, so always the first container element is retrieved,
without any warning/error (which could be considered a bug of its own).

The attached patch implements the XNameAccess support.
Comment 1 Frank Schönheit 2008-06-30 21:16:24 UTC
Created attachment 54846 [details]
patch
Comment 2 Frank Schönheit 2008-06-30 21:21:42 UTC
Created attachment 54847 [details]
patch with -b, for better readability of what is done
Comment 3 bmarcelly 2008-07-01 09:52:13 UTC
-> fs
Remember that Basic already accepts a shortcut to .getByName :

oSheet = ThisComponent.Sheets.getByName("prettyName")
'  -- or --
oSheet = ThisComponent.Sheets.prettyname

Some people already use this shortcut (but I don't like it). Notice that the element 
name is not case sensitive with this method.

The introduction of container("elementName") could be useful in a VBA mode. In a pure 
OOoBasic mode you have to be aware of possible conflict with container(index) method.

Currently you can do:
oSheet = ThisComponent.Sheets(1)
oSheet = ThisComponent.Sheets("1")  ' string is converted to a number, perfectly licit

And there is the common error :
oSheet = ThisComponent.Sheets("Feuille1") ' converts to zero, and gets Sheets(0) 
without error

Comment 4 Frank Schönheit 2008-07-01 10:55:54 UTC
> Currently you can do:
> oSheet = ThisComponent.Sheets(1)
> oSheet = ThisComponent.Sheets("1")  ' string is converted to a number,
>   perfectly licit

Uhm - if we want to support this case (and I suppose for compatibility reasons
we want), then the patch is bogus :(

> And there is the common error :
> oSheet = ThisComponent.Sheets("Feuille1") ' converts to zero, and gets
>   Sheets(0) without error

Which is exactly what I stumbled upon - and why I created the patch ...
Comment 5 ab 2008-07-03 13:34:13 UTC
I will have a look... STARTED, 3.x
Comment 6 ab 2008-08-12 11:22:04 UTC
Regarding the compatibility concerns I would prefer to keep the Basic
default behaviour and address this in the scope of the VBA mode.
Does anyone have a problem with this? WONTFIX for now.
Comment 7 Mechtilde 2008-11-06 21:27:42 UTC
close the invalid issue