UNO API with Basic

Apologies for this rooky questions : I am still a bit confused in working with BASIC and LO API. I was used in the past to develop with OSF/DCE and all its inticacies.

As stated here [Handling UNO Objects - Apache OpenOffice Wiki]

In Java and C++, it is necessary to obtain a reference to each interface before calling one of its methods. In Basic, every method of every supported interface can be called directly at the object without querying for the appropriate interface in advance. The ‘.’ operator is used:
Additionally, Apache OpenOffice Basic interprets pairs of get and set methods at UNO objects as Basic object properties if they follow this pattern:

  • SomeType getSomeProperty()*
  • void setSomeProperty(SomeType aValue)*

My working paradigm is to use MRI / Xray to scan properties, methods, service etc. and, by looking at the various classes, trying to access the item (property or method). This works most of the time. My question however is the following:

  1. Are all relevant properties and methods available in BASIC ?
  2. If yes, where can I find a reference of the various BASIC modules/services to call ? e.g. if I ha this piece of code:

oDoc = ThisComponent
oForm = oDoc.Drawpage.Forms

Which classes am I precisely using ? Does a list of BASIC UNO service exist ?

Thanks.

Dim oDoc as object
Dim oForms as object

 oDoc = ThisComponent
 oForm = oDoc.Drawpage.Forms

Only the Dim statement is related to the StarBasic. All of other things are related to the LO API.
https://api.libreoffice.org/
https://api.libreoffice.org/docs/idl/ref/annotated.html

I am using the XrayTool with StarBasic. (It works fine with the StarBasic too.) In my opinion is is easier than seaching in a huge API description.

Thank you Tibor.

1 Like

For the sake of learning I have tried to write Basic macros for doing what is done in these examples:

https://wiki.openoffice.org/wiki/Documentation/DevGuide/Forms/FormComponents_Service
https://wiki.openoffice.org/wiki/Documentation/DevGuide/Forms/Control_Models

I am basically trying to dump a form components’ tree. It works, I however do not correctly determine the control type. I get the numeric format. I have tried with supprted services without success. Any help ?

REM ***** BASIC *****
Sub Main
Dim Doc As Object
Dim DrawPage As Object
Dim Form As Object
Dim Forms As Object
Dim tree as String

Doc = ThisComponent	
DrawPage = Doc.DrawPage
Forms = Doc.DrawPage.getForms()

Scan(Forms.GetByIndex(0), "", tree)
MsgBox(tree)

End Sub

Sub Scan (o as Object, indent as String, tree as String)
Dim i as Integer
Dim sElementNames() as String
Dim p as Object
Dim q as Object
Dim svcs(64) as String
Dim ss as String
Dim sClassId as String

p = o.getPropertySetInfo()
if ( not isnull(p) AND p.hasPropertyByName("ClassId") ) then
	sClassId = o.getPropertyValue("ClassId")
else
	sClassId = "-"
end if

if (hasUnoInterfaces(o, "com.sun.star.form.XFormComponent", "com.sun.star.container.XContainer")) then	
	sElementNames = o.GetElementNames()    
	tree = tree + indent + " [ " + o.Name + " ]  [ " + ubound(sElementNames) + " ] Class [ " + sClassId + " ] " + ss + CHR(10)
	For I = 0 To ubound(sElementNames)
		Scan(o.GetByIndex(I), "____" + indent, tree)
	Next I

else
tree = tree + indent + " [ " + o.Name + " ] [ " + ubound(sElementNames) + " ] Class [ " + sClassId + " ] " + ss + CHR(10)
exit sub
end if

End Sub

ClassId has type Short. See also FormComponentType.

MRI-menu:Tools>Configuration…
On my Linux system it looks like this:
SDK directory: file:///opt/libreoffice7.5/sdk/
[X] generated by Doxygen
Browser path: file:///usr/bin/firefox

Now you get a direct link to the documentation almost everything. Just put the cursor on some MRI line and hit the [IDL Ref] button.

Or
https://api.libreoffice.org/

Man thanks : I am trying to learn how to use UNO constants from BASIC … do you have an example ?

Will install teh SDK now … thanks

I’m afraid it won’t work - our site uses different structure, so the extension will generate non-working URLs.

Solution found :slight_smile:

	Select Case sClassId
	
		case com.sun.star.form.FormComponentType.COMMANDBUTTON			
			MsgBox "Command Button"
			
		case com.sun.star.form.FormComponentType.LISTBOX
			MsgBox "List Box"
			
		case com.sun.star.form.FormComponentType.GRIDCONTROL
			MsgBox "Grid Control"
			
		case com.sun.star.form.FormComponentType.TEXTFIELD
			MsgBox "Text Field"
			
	End Select

Many thanks

This old document can sometimes be helpful:
Star Basic Programmers Guide

Good reference. This, and many other sources, are linked from our macro documentation wiki page.

1 Like

Hi Donald, I remember to have seen this document a very long time ago : I am reading it and it’s really good stuff !

Really appreciated.