Indirect access to object method

asked 2020-07-21 20:56:15 +0200

torreone gravatar image

updated 2020-07-22 15:01:48 +0200

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 flag offensive 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?

JohnSUN gravatar imageJohnSUN ( 2020-07-21 21:06:28 +0200 )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 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 ?

torreone gravatar imagetorreone ( 2020-07-21 21:37:56 +0200 )edit

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

Mike Kaganski gravatar imageMike Kaganski ( 2020-07-21 22:00:29 +0200 )edit

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

torreone gravatar imagetorreone ( 2020-07-21 22:24:49 +0200 )edit

@Mike Kaganski: Why not make an answer of your comment?

Lupp gravatar imageLupp ( 2020-07-22 12:27:32 +0200 )edit

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

Mike Kaganski gravatar imageMike Kaganski ( 2020-07-22 12:35:16 +0200 )edit

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("")
  oObjInfo = oSpec.inspect( oParagraph )  
  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

torreone gravatar imagetorreone ( 2020-07-22 14:55:09 +0200 )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 ..

Lupp gravatar imageLupp ( 2020-07-22 19:41:31 +0200 )edit

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

torreone gravatar imagetorreone ( 2020-07-22 21:34:38 +0200 )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.

torreone gravatar imagetorreone ( 2020-07-22 21:37:43 +0200 )edit