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

edit retag close merge delete

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?

( 2020-07-21 21:06:28 +0100 )edit

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 https://ask.libreoffice.org/en/questi... 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 ?

( 2020-07-21 21:37:56 +0100 )edit
2

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

( 2020-07-21 22:00:29 +0100 )edit

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

( 2020-07-21 22:24:49 +0100 )edit

( 2020-07-22 12:27:32 +0100 )edit
1

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

( 2020-07-22 12:35:16 +0100 )edit
2

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

( 2020-07-22 14:55:09 +0100 )edit

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 @Mike Kaganski ..
https://extensions.libreoffice.org/en...
https://forum.openoffice.org/en/forum...

( 2020-07-22 19:41:31 +0100 )edit

Thanks Lupp. I am using mri with some limits because under linux I can't see the menus of mri and this technique (https://ask.libreoffice.org/en/questi...) 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)

( 2020-07-22 21:34:38 +0100 )edit

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.

( 2020-07-22 21:37:43 +0100 )edit