Unexpected ThisComponent fail

Discuss the database features

Unexpected ThisComponent fail

Postby arfgh » Thu Oct 12, 2017 6:14 pm

Conforming the explained here: https://wiki.openoffice.org/wiki/Docume ... /Documents

i had an unexpected result working with several form windows and frames at same time.
That doc in the said url is saying that 'thisComponent' is the correct way to obtain the current document location and not 'StarDesktop.CurrentComponent'.
But detecting resolution of all the opened windows 'thisComponent' kept referring to the first opened window form, instead of the active window.
It was very strange for me because that doc in the said url is very EXPLICIT, and curiously i obtained the correct result using 'StarDesktop.CurrentComponent' and not the famous 'thisComponent'.

think about ?
OpenOffice last version - Windows 8.1 Enterprise x64 - Windows XP x64 SP2
Posts: 385
Joined: Tue Mar 05, 2013 6:44 pm

Re: Unexpected ThisComponent fail

Postby RoryOF » Thu Oct 12, 2017 6:38 pm

thisComponent returns the current document from which the macro is run. You need to cycle through the open components using some other UNO construct
Apache OpenOffice 4.1.5 on Xubuntu 18.04 (mostly 64 bit version) and infrequently on Win2K/XP
User avatar
Posts: 27312
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Unexpected ThisComponent fail

Postby Villeroy » Thu Oct 12, 2017 7:45 pm

Until today I do not get the difference between a model and a component. In my understanding, both mean "document".

ThisComponent is the embedding document of a macro (except Base, sigh).
ThisDatabaseDocument is the embedding database document of a macro.
ThisComponent is the active document (including Base document) if the code is in runnin in global scope ("My Macros" or "XOffice Macros")

ThisComponent in global scope includes help documents which gives unexpected results when you try to get ThisComponent.getSheets() while the last active window was a help window.
ThisComponent does not include the Basic IDE which makes it possible to run code from the IDE. ThisComponent.getSheets() is possible while the IDE is active and the previously active document was a spreadsheet.

StarDesktop.getCurrentModel() is the same as ThisComponent in global scope but this one includes the Basic IDE so you have to call the macro while the intended document is the active one.

StarDesktop.getFrames() may be useful. Every frame has one controller (not so sure; are there any frames without controller?) and the controller may have a model or not. For instance, an MRI frame or the frame of the start screen has a controller to interact with but it has no model.
You can loop through all frames, and test if its controller has a model and then the ImplementationName of the model.
A Writer document with no URL could be a new document or an embedded form. I think you have to add some distinctive property. I would add a unique identifier in the form's document properties (menu:File>Properties... Title, Subject, Keywords or something user defined).
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, OpenOffice 4.x & LibreOffice 6.x
User avatar
Posts: 25752
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Return to Base

Who is online

Users browsing this forum: No registered users and 3 guests