Bug 51925 - [BASIC] Writer Table getColumns().getByIndex(i) returns null, where it should not
Summary: [BASIC] Writer Table getColumns().getByIndex(i) returns null, where it shoul...
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
3.5.4 release
Hardware: Other All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Macro-UNOAPI
  Show dependency treegraph
 
Reported: 2012-07-09 19:37 UTC by Olivier Hallot
Modified: 2024-02-29 07:03 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
Text document showing bug in getColumns.getByIndex() flaw. (10.27 KB, application/vnd.oasis.opendocument.text)
2012-07-09 19:37 UTC, Olivier Hallot
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Hallot 2012-07-09 19:37:08 UTC
Created attachment 64047 [details]
Text document showing bug in getColumns.getByIndex() flaw.

The following piece of BASIC returns a null object where it should not.

REM  *****  BASIC  *****

Sub Main
nLin = 10
nCol = 7

oText = ThisComponent.getText()
oText.setString("")
oText.getStart()		

'Create tabela
	oTabela = ThisComponent.createInstance("com.sun.star.text.TextTable")
	oTabela.initialize ( nLin, nCol )
	oTabela.setName("test")
	oCursorT = oText.createTextCursor()
	oText.insertTextContent(oCursorT, oTabela, True)
        oColuna = oTabela.getColumns().getByIndex(0)
        xray oColuna
	'oColuna.IsAutoWidth = False
	'oColuna.Width = 4440
End Sub

oColuna returns NULL where it should have returned an object. xray is a well known macro to inspect objects.

No way to set a column width, and other column properties.

The attached document provides a living example.

Please execute macro Main in Standard library.
Comment 1 Olivier Hallot 2012-07-15 03:14:31 UTC
getByIndex() is not working fot columns, work for rows.
Comment 2 Olivier Hallot 2012-07-20 13:51:19 UTC
A complete description of why this stupid situation is there:

https://issues.apache.org/ooo/show_bug.cgi?id=21669.

In a nutshell: the getByIndex() method is there to fulfill the API completness, but it wasn't implemented, and deliberately returns NULL.
Comment 3 bfoman (inactive) 2013-01-28 12:28:17 UTC
https://issues.apache.org/ooo/show_bug.cgi?id=21669 status:
CLOSED FIXED

https://issues.apache.org/ooo/show_bug.cgi?id=21669#c7:
[...]
Fixed in CWS tl14.
Files changed:
- unotbl.cxx  new revision: 1.91.168.1
Comment 4 tommy27 2013-10-19 18:55:54 UTC
adding BASIC expert to CC  list
Comment 5 Joel Madero 2014-07-21 01:41:54 UTC
@Olivier - I get a basic runtime error with your sample - is this what you are referring to or should I be seeing something different?
Comment 6 Noel Power 2014-07-21 08:20:12 UTC
(In reply to comment #4)
> adding BASIC expert to CC  list

it's got nothing to do with basic, it's according to comment #2 and api implementation issue
Comment 7 tommy27 2014-07-21 08:52:24 UTC
sorry Noel for disturbing you. my bad :-)
Comment 8 Owen Genat (retired) 2014-07-28 11:45:15 UTC
I think according to comment 2 and comment 6 this report can be confirmed. As comment seven in the related Apache issue indicates, /core/sw/source/core/unocore/unotbl.cxx was changed back in 2005 to return null because "the internal table representation does not have columns".

The related change appears to be 904d699f6d76154e541c35395c69d6c85712ec2a which states: 2005/07/13 13:37:25 tl 1.91.168.1: #i21669# SwXTableColumns::getByIndex returns an empty XInterface now.

Exactly how the issue might be resolved remains a problem, but the report at least would seem accurate. Apache issue added to See Also list for reference. Status set to NEW.
Comment 9 QA Administrators 2015-09-04 02:48:47 UTC Comment hidden (obsolete)
Comment 10 Olivier Hallot 2015-09-04 11:26:36 UTC
The bug is still valid as of today, any version.
Comment 11 QA Administrators 2016-09-20 10:29:58 UTC Comment hidden (obsolete)
Comment 12 Buovjaga 2019-08-11 10:39:12 UTC
Original macro seems to require Xray extension to be installed. I tested with MsgBox(oColuna) instead (empty result and "Object variable not set")

Arch Linux 64-bit
Version: 6.4.0.0.alpha0+
Build ID: 37fc9f51a8de11d40632e8cda17ccf1fa4b1f503
CPU threads: 8; OS: Linux 5.2; UI render: default; VCL: gtk3; 
Locale: fi-FI (fi_FI.UTF-8); UI-Language: en-US
Calc: threaded
Built on 6 August 2019
Comment 13 QA Administrators 2021-09-19 03:44:54 UTC Comment hidden (obsolete)
Comment 14 QA Administrators 2023-09-20 03:06:20 UTC Comment hidden (obsolete)
Comment 15 sander 2024-02-29 07:03:55 UTC
The problem still exists: BASIC-runtime-fout.
Objectvariabele niet ingesteld.

My macro:
Sub test3
    Dim oDoc As Object
    Dim oTables As Object
    Dim oTable As Object
    Dim i As Integer
    
    ' Haal het huidige document op
    oDoc = ThisComponent
    
    ' Haal alle tabellen in het document op
    oTables = oDoc.getTextTables()
    
    ' Loop door elke tabel en pas de kolombreedtes aan
    For i = 0 To oTables.getCount() - 1
        oTable = oTables.getByIndex(i)
        oTable.Columns.getByIndex(0).Width = 8900 ' 8,9 cm
        oTable.Columns.getByIndex(1).Width = 1000 ' 1 cm
        oTable.Columns.getByIndex(2).Width = 9700 ' 9,7 cm
    Next i
End Sub

Error occurs on: oTable.Columns.getByIndex(0).Width