[Solved][Base] Access a SubSubForm with getByIndex() method

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
pinco pallo
Posts: 89
Joined: Tue Jul 16, 2013 2:24 pm

[Solved][Base] Access a SubSubForm with getByIndex() method

Post by pinco pallo »

Hi everyone,
i saw that i can access a SubForm using this code:

Code: Select all

oForm=thisComponent.drawpage.forms.getByIndex(0).getByIndex(0)
but it doesn't work for the next SubSubForm level:

Code: Select all

oForm=thisComponent.drawpage.forms.getByIndex(0).getByIndex(0).getByIndex(0)
while it works well:

Code: Select all

oForm=thisComponent.drawpage.forms.getByIndex(0).getByIndex(0).getByName("SubSubFormName")
Is there a limitation on the use of the getByIndex() method?
Thank you in advance.
Last edited by pinco pallo on Sun May 03, 2020 11:36 am, edited 1 time in total.
LiBO 6.2.8.2 on macOS 10.12.6 (Sierra)
User avatar
Mr.Dandy
Posts: 427
Joined: Tue Dec 11, 2012 4:22 pm

Re: [Base] Access a SubSubForm with getByIndex() method

Post by Mr.Dandy »

Hello,

Save our time and provide this ODB.
We can have a look at your problem.
OpenOffice 4.1.12 - Windows 10
pinco pallo
Posts: 89
Joined: Tue Jul 16, 2013 2:24 pm

Re: [Base] Access a SubSubForm with getByIndex() method

Post by pinco pallo »

Hello, here is my example where macros Print1, Print2, Print4 works well. Macro Print3 doesn't work and show error message.
Thank you.
Attachments
New Database.odb
(14.82 KiB) Downloaded 149 times
LiBO 6.2.8.2 on macOS 10.12.6 (Sierra)
JeJe
Volunteer
Posts: 2784
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Base] Access a SubSubForm with getByIndex() method

Post by JeJe »

You can investigate these things easily with MRI, doing so

oForm = oDrawpage.forms.getByIndex(0).getByIndex(0).getByIndex(0)
mri oForm

oForm looks to be the label "lblId"
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
pinco pallo
Posts: 89
Joined: Tue Jul 16, 2013 2:24 pm

Re: [Base] Access a SubSubForm with getByIndex() method

Post by pinco pallo »

Sorry, I doesn't understand. I don't know MRI (but I have installed it in my Libo).
LiBO 6.2.8.2 on macOS 10.12.6 (Sierra)
JeJe
Volunteer
Posts: 2784
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Base] Access a SubSubForm with getByIndex() method

Post by JeJe »

You load the MRI eg with
Globalscope.BasicLibraries.LoadLibrary( "MRILib" )

You can then inspect any object by typing

MRI object

Doing that you can see what you think is a form at index 0, isn't.

(To help people answer your query, if you're using Libo you should have that instead of/as well as "AOO 4.1.3 on Mac OSX" for you app/os)
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2784
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Base] Access a SubSubForm with getByIndex() method

Post by JeJe »

All you have is the wrong index - its 6 for the form you want

Code: Select all

Sub Print3 ' it doesn't work 
	Dim oDoc As Object
	Dim oDrawpage As Object
	Dim oForm As Object
	Dim sName As string
	oDoc = thisComponent
	oDrawpage = oDoc.drawpage
	oForm = oDrawpage.forms.getByIndex(0).getByIndex(0).getByIndex(6)
	sName = oForm.getByName("State").text
	print sName
End Sub
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Base] Access a SubSubForm with getByIndex() method

Post by Villeroy »

[Tutorial] Introduction into object inspection with MRI
Do NOT access form elements by index unless you are very sure that you never change anything on these forms.
Instead of pulling forms from the DrawPage you could also follow an event driven programming approach. Every form event passes over some kind of event struct where the Source element refers to the calling object.

Code: Select all

Sub ControlEvent(oEv)
oCallingThing = oEv.Source
oForm = oCallingThing.getParent()
REM in rare cases where the caller is embedded in a table grid:
oForm = oCallingThing.Parent.getParent()

Sub SubFormEvent(oEv)
oSubForm = oEv.Source
oForm = oEv.getParent()

Sub FormEvent(oEv)
oForm = oEv.Source
This way you are right in the middle of where the music plays without crossing the entire hierarchy
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
pinco pallo
Posts: 89
Joined: Tue Jul 16, 2013 2:24 pm

Re: [Base] Access a SubSubForm with getByIndex() method

Post by pinco pallo »

Thanks @JeJe e @Villeroy, I understand that the getByIndex () method does not give fixed results as I thought.
I also discovered a new way: I will study MRI to learn how to use it well. Thanks again !!
LiBO 6.2.8.2 on macOS 10.12.6 (Sierra)
Post Reply