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

Creating a macro - Writing a Script - Using the API

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

Postby pinco pallo » Sat May 02, 2020 8:29 am

Hi everyone,
i saw that i can access a SubForm using this code:
Code: Select all   Expand viewCollapse view
oForm=thisComponent.drawpage.forms.getByIndex(0).getByIndex(0)

but it doesn't work for the next SubSubForm level:
Code: Select all   Expand viewCollapse view
oForm=thisComponent.drawpage.forms.getByIndex(0).getByIndex(0).getByIndex(0)

while it works well:
Code: Select all   Expand viewCollapse view
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)
pinco pallo
 
Posts: 89
Joined: Tue Jul 16, 2013 2:24 pm

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

Postby Mr.Dandy » Sat May 02, 2020 11:16 am

Hello,

Save our time and provide this ODB.
We can have a look at your problem.
OpenOffice 4.1.7 - Windows 10
User avatar
Mr.Dandy
 
Posts: 314
Joined: Tue Dec 11, 2012 4:22 pm

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

Postby pinco pallo » Sat May 02, 2020 12:40 pm

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 18 times
LiBO 6.2.8.2 on macOS 10.12.6 (Sierra)
pinco pallo
 
Posts: 89
Joined: Tue Jul 16, 2013 2:24 pm

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

Postby JeJe » Sat May 02, 2020 1:30 pm

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"
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 1088
Joined: Wed Mar 09, 2016 2:40 pm

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

Postby pinco pallo » Sat May 02, 2020 2:07 pm

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)
pinco pallo
 
Posts: 89
Joined: Tue Jul 16, 2013 2:24 pm

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

Postby JeJe » Sat May 02, 2020 2:19 pm

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)
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 1088
Joined: Wed Mar 09, 2016 2:40 pm

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

Postby JeJe » Sat May 02, 2020 2:30 pm

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

Code: Select all   Expand viewCollapse view
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
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 1088
Joined: Wed Mar 09, 2016 2:40 pm

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

Postby Villeroy » Sat May 02, 2020 3:06 pm

[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   Expand viewCollapse view
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, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28431
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Postby pinco pallo » Sun May 03, 2020 11:36 am

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)
pinco pallo
 
Posts: 89
Joined: Tue Jul 16, 2013 2:24 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 4 guests