Indirect macro invocation with object argument

The Application Programming Interface and the OASIS Open Document Format

Indirect macro invocation with object argument

Postby DavidHMcCracken » Sat Jan 16, 2021 7:38 am

I have registered a function to be invoked whenever any document is opened. Since only one macro can be assigned to this event, I want my function to play nicely by invoking macros specified by a user-defined list of similar functions in other libraries. Obviously, these functions cannot be embedded in mine and must, therefore, be invoked indirectly, i.e. by name as string. This "indirect" invocation is not difficult if no arguments or only string arguments are needed but the argument to this function is an object. Not passing the argument, the indirect invocation of each chained function is:
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(ThisComponent.CurrentController.Frame, "macro:///" & LibModuleFunctionString, "", 0, Array())

This is a general question but I have provided the context to explain how this could be useful and also to invite completely different solutions to my immediate problem.
W10 Libre 6.1.5.2 and Ubuntu-Mate 18.04 Libre 6.0.7.3
DavidHMcCracken
 
Posts: 43
Joined: Tue Apr 10, 2018 6:15 am

Re: Indirect macro invocation with object argument

Postby Zizi64 » Sat Jan 16, 2021 9:05 am

PLease upload more samples (the code of the macros to call, and a sample document where you want to to call the macros from.)

You can call your own (user defined) macros by their name and by the passed parameters, not needed the Dispacther.
The Dispatcher is excellent (for example) to call the Calc Cell functions from a macro.

Code: Select all   Expand viewCollapse view
sub My_main_routine

my_routine1("constant string parameter", sStringVariable)

floatResult = my_function2(floatNumberVariable1; floatNumberVariable2)

my_routine3(floatResult, floatNumberVariable3)

end sub


You can assingn the My_main_routine to the document event. It will call all of others routines and functions.
It can call the subs and functions from the MyMacros Standard library and/or from the Standard library of the actual document.

These libraries (the Standard ones) will be loaded into the memory, automatically. You must load-in the other libraries before you call a routine/function from them:

Code: Select all   Expand viewCollapse view
...
If (Not GlobalScope.BasicLibraries.isLibraryLoaded("MyLibrary1")) Then
      GlobalScope.BasicLibraries.LoadLibrary("MyLibrary1")
   End If
...
Tibor Kovacs, Hungary; LO6.1.6, 6.4.7 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.1.1;AOO4.1.9
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 9843
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Indirect macro invocation with object argument

Postby DavidHMcCracken » Sat Jan 16, 2021 7:26 pm

Thank you Zizi64 for your quick reply. Unfortunately, my situation is more complex than that. Indeed, my "on document open" macro does call several others, as you suggest, but they are all known at compile time and can be invoked directly. If the macro is not known until run time it must be invoked by reference. In C/C++ this is done with a pointer, in LISP with a delayed dereference operator. In BASIC I think it can only be done with a string passed to a mechanism that will interpret the string as a reference to a macro. Dispatcher is the only means that I have found. It does work but I can't find a way to pass an object argument to the macro. I'm hoping that someone either knows how to do that or can suggest an alternative means of invoking a macro that is not known until run time.
W10 Libre 6.1.5.2 and Ubuntu-Mate 18.04 Libre 6.0.7.3
DavidHMcCracken
 
Posts: 43
Joined: Tue Apr 10, 2018 6:15 am

Re: Indirect macro invocation with object argument

Postby JohnSUN-Pensioner » Sat Jan 16, 2021 8:13 pm

Perhaps this solution will help you move on.
I may not have a lot to give but what I got I'll give to you...
Apache OpenOffice 4.1.5, LibreOffice 6.4.4.2 (x64) on Windows 7
If you think that I did not answer your question, make allowances for my imperfect English
User avatar
JohnSUN-Pensioner
Volunteer
 
Posts: 845
Joined: Fri Jan 14, 2011 1:21 pm
Location: Kyiv, Ukraine

Re: Indirect macro invocation with object argument

Postby Villeroy » Sat Jan 16, 2021 8:18 pm

The stupid StarBasic language ignores any parameters as long as they remain unreferenced. Install the MRI extension and read [Tutorial] Introduction into object inspection with MRI
Bind your event to MyMacros>MriLib>Module1.Mri
This will show an object inspection window with all properties of the passed event struct, including the "Source" element which is the calling object.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
 
Posts: 29727
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany


Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 2 guests