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 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 ?
Using XIntrospection, get access to the object's methods; then you may obtain a
XIdlMethod
, and use itsinvoke
.Many thanks Mike! I didn't know this interface. Now I study and try it
@Mike Kaganski: 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 :-)
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
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 @Mike Kaganski ..
https://extensions.libreoffice.org/en...
https://forum.openoffice.org/en/forum...
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)
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.