Indirect access to object method

Is it possible in starbasic to call the method of a byname object, therefore indirectly?
A method like obj.callByName (“getString”) instead of obj.getString ()?

For some properties this technique exists using the getPropertySetInfo object. For the methods I can’t find something like this

Thanks in advance for any suggestions

Edit 7/22/2020 → Modified post tags and proposed a minimal solution following Mike’s reply

I don’t know of such a possibility. But I wondered - what scenario would you like to implement if such an indirect method call existed? For what tasks might you need this way of calling built-in methods?

I was trying to create a generalized function to scan a series of objects (e.g. paragraphs) to filter only those in which a generic property, passed as a string name, satisfied a given condition.

This is possible with the properties supported by getPropertySetInfo, accessing in indirect mode to properties passing the string name

But many “properties” (eg “string”) are pseudo-properties. Their value should be read with methods (e.g. getString ()). And I can’t do this

Here Function to return properties of an object rather than their names aims to build a function on the fly in a dummy library. I think it works, but every creation corresponds, I think, with a recompilation of all the libraries.
Or am I wrong ?

Using XIntrospection, get access to the object’s methods; then you may obtain a XIdlMethod, and use its invoke.

Many thanks Mike! I didn’t know this interface. Now I study and try it

@mikekaganski: Why not make an answer of your comment?

@Lupp: the same reason: I point to a direction, but have no intention to do the necessary research to prepare a proper answer :slight_smile:

I found very few examples and only in java (which I don’t know). Following Mike’s directions, I managed to code this first working minimal example (what I needed) in StarBasic.
oParagraph is a reference to any paragraph

  oSpec = CreateUnoService("com.sun.star.beans.Introspection")
  oObjInfo = oSpec.inspect( oParagraph )  
  oMeth=oObjInfo.getMethod("getString",-1)
  s=oMeth.invoke(oParagraph,array())   ' analog to oParagraph.getString()

I am trying to deepen this interface that I didn’t know before Mike’s help and which is very little talked about on the net, although it seems really powerful.

As soon as I can I will try to give a more thorough answer and a mini-tutorial, if it can be useful

Thanks again Mike

You surely know XRay and MRI extensions?
If not, you should be interested. In specific MRI (written in Python) is told to make deep use of the interfaces mentioned by @mikekaganski
https://extensions.libreoffice.org/en/extensions/show/mri-uno-object-inspection-tool
https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=86461

Thanks Lupp. I am using mri with some limits because under linux I can’t see the menus of mri and this technique (MRI menus not working) I can’t make it work

By combining getPropertyValue, getPropertySetInfo and the four lines of code from my comment yesterday, you should already be able to indirectly access almost all the properties / methods of an object.

And this already allows you to filter objects in a programmed and parameterized way during an access using enumeration

The introspection and introspectionAccess objects and their interfaces are powerful but not immediate to use

For example, the hasProperty method in introspectionAccess tells me that the “string” property of a paragraph exists, but hasPropertyByName from getPropertySetInfo tells me otherwise (and in fact the value must be obtained with the getString () method)

For now I can’t understand in starbasic how to make the queryAdapter method work, I haven’t found any application example in starbasic on the net, only in java (which I don’t know)

The other methods seem clear enough to me.

For example, the hasProperty method in introspectionAccess tells me that the “string” property of a paragraph exists, but hasPropertyByName from getPropertySetInfo tells me otherwise

See getProperty’s nPropertyConcepts parameter. It allows you to tell if you need all properties, or only from property set, or those using dedicated getter/setter methods, …

it’s true, I probably used hasPropertyByName incorrectly by searching all properties, for now I have always used nPropertyConcepts = -1 (search all).
If run this code, zzhAll=true, zzh2=zzh4=false (“String” is a pseudo-property and is not an attribute)
In reverse,zzh8=true, because “string” is represented by getter or setter methods. (see Constants' Group PropertyConcept)

  oSpec = CreateUnoService("com.sun.star.beans.Introspection")
  oObjInfo = oSpec.inspect( oParagraph )  
  zzhAll=oObjInfo.hasProperty("String",-1) 
  zzh2=oObjInfo.hasProperty("String",2) 
  zzh4=oObjInfo.hasProperty("String",4) 
  zzh8=oObjInfo.hasProperty("String",8) 

So hasPropertyByName returns “exist” but considering that the value is obtained from the getString () method. It has its own logic.

Here, Interface XIntrospectionAccess I see that the
queryAdapter method outuput an interface (:: com :: sun :: star :: :: one XInterface)
but asks for the following format queryAdapter ([in] type aInterfaceType)

Do you know how to write to InterfaceType? Is it an object? A string?