Attempting to 'master' the UNO api

I am trying to understand the use of the UNO api. Although I have a lot of experience with Java and Android programming I now want to learn LibreOffice Base Macro’s and especially Basic and the use of the UNO environment.
I did not find a good tutorial until now, so it is HARD!
I have already succeeded in writing some Basic in which I make use of UNO parts, which I discovered myself. But now I have a problem:
From LibreOffice Help I copied something like "form = ThisDatabaseDocument.FormDocuments.getByName(“formName”).open
According to the help text ThisDatabaseDocument is an object returned by XOfficeDatabaseDocument. The problem is the next part, FormDocuments. I can not find what it is in relation to the OfficeDatabaseDocument and where to find it in the UNO.
I have the feeling that when this question is solved, the UNO structure will become much clearer to me. Who can help me?

Hello,

As you must be aware of by now, documentation for api is kind of scattered.

Here is LO API Reference > Namespace List
For Base much is under com.sun.star.sdb

Some good information here > The Apache OpenOffice Wiki
See especially Development Guide under Documentation section.

Also important are the links in my comment here > Auto-populate table with default values via form Also link in comment below it.

And this may interest you > ThisDatabaseDocument vs ThisComponent?

Edit:

Sorry but I forgot to note that FormDocuments is the container for the forms in current Base file. There is also a container for Reports and for Queries.

Thank you for your reply! It looks that I have something to read and to do the Next weeks, months… :smiley:!

Hello,
I have been struggling with it for several days now, but I don’t seem to get any further.
I am almost at the point of giving it all up now.
I also think that my LibreOffice installation (7.3.1.3) may not be complete, because of the following:

  • I have activated code completion, but whatever I do it does not work.
  • When I open the chapter ‘ThisComponent Object’ in the LibreOffice help I see a nice example. But after copying it and paste it in the IDE I get the following error after starting it: “Property or method not found: getDocumentindexes”.
  • The same help text also says: Properties and methods available through ThisComponent depend on the document type. Ok that is very nice but where can I find all these methods and properties?

I have the feeling of working in complete darkness now.

I have another example, what is wrong in the following code:

Sub Tst
Dim Statement As Object
Dim ResultSet As Object
Statement = CreateUnoService("com.sun.star.sdbcx.Statement")
ResultSet = Statement.executeQuery("SELECT ""name"" FROM ""Customers""") 

If Not IsNull(ResultSet) Then
  While ResultSet.next
    MsgBox ResultSet.getString(1)
  Wend
End If
End Sub

Whatever I try, I always get the following error on the ResultSet line:
BASIC runtime error Object variable not set

The code is running from the IDE of the database.

Hello,
Understandably you have many questions. Also understand this is a question and answer site.

It took me months not days to start actually comprehending some of what is going on. After many years now, still learning the API. I see no need to know all as so much is not what I am interested in.
.
Go back to my first comment. There is a link for ThisDatabaseDocument vs This component?. This is essential in seeing the manner in which and item depends upon the document type.
.
The link above that regarding Auto-populate table contains a link to MRI & how to use it. @Villeroy has also brought this to your attention. Without using this you will struggle all the more.
.
As for your sample code, there is no connection to a database for “Statement”. Unfortunately, as with many items in the API there are multiple ways to do this. See this post for two methods > Executing SQL Statements from Forms with macros .
For your code try:

Sub Tst
Dim Statement As Object
Dim ResultSet As Object
      if IsNull(ThisComponent.CurrentController.ActiveConnection) then
       ThisComponent.CurrentController.connect
    endif
    Statement = ThisComponent.CurrentController.ActiveConnection.createStatement()
    Statement.ResultSetType = com.sun.star.sdbc.ResultSetType.SCROLL_SENSITIVE
    ResultSet = Statement.executeQuery("SELECT ""name"" FROM ""Customers""") 
    Dim CursorTest AS Boolean
	CursorTest = ResultSet.first
	If CursorTest = "False" Then
        MsgBox "Record not found"
        Exit Sub
    End If
    ResultSet.beforeFirst()
    While ResultSet.next
        MsgBox ResultSet.getString(1)
    Wend
End Sub

Also see > Moving the Result Set Cursor
.
Hope this helps.

Hello,
Thank you for your encouraging words. Giving up would feel as a disappointment.
I am going to look at your earlier link, starting with the MRI-thing.
I realize it will take time, but that is what I have after being retired.
Kind regards!

Have you already discovered the Handbook on Base? There are actual manuals at LibreOffice.org usually at Documentation under getting Help.

I only read the german one, but it includes also a chaptet on macros and there are several examples…

Thank you for your reply. I indeed discovered the Handbook.

You don’t have to struggle with an archaic Basic dialect. BeanShell (interpreted Java) should work as well. The API you talk to in either language is always the same. This API is a monster from hell, though.
The MRI extension is inevitable. It is an object inspector with built-in code generator for Basic, Java, Python and JavaScript. [Tutorial] Introduction into object inspection with MRI.

Thank you for your reply! Struggling with it is a challenge for me, :rofl:

If you are working in Python then checkout python-ooouno

It is the entire current LibreOffice API written in Python.
I am the author of the library and I just release it yesterday.
Cheers