# Base: another way to say ThisComponent? [closed]

While trying to open a form at startup directly in Base via an LO Basic macro, I see the virtue of having an alternative way to step into the LibreOffice object hierarchy. Upon the Open Document event, the global ThisDatabaseDocument never works, and the alternative ThisComponent will sometimes at first return an unexpected error: no introspection available:

That, of course is only the error telling me I cannot tell the properties of ThisComponent; the functional error is that ThisComponent does not at the very first have any of the anticipated properties or methods.

In one of the charming quirks about LO Basic, if you Wait 50 then things often go back to the way they should have been at the first, but this leads me to the question: Does anyone know an alternative syntax for accessing the object hierarchy in Base, like the calls that would create the ThisComponent global variable from scratch? Perhaps the kind of syntax prevalent pre-2009 using something like com.sun.star.sdb.aplication.DatabaseObject.FORM or com.sun.star.document.OfficeDocument -- things like that. Would I need to write the macro in Java? Or, perhaps a way to call the document controller via another method.

I think the document-level events do not pass an event object to the macro, so that does not appear to be a possibility.

edit retag reopen merge delete

### Closed for the following reason question is not relevant or outdated by Alex Kemp close date 2020-07-21 01:34:56.101279

Using LO 5.2.3.3 I get the same problem: ThisDatabaseDocument is missing.

( 2017-05-10 07:16:07 +0200 )edit

There is now a good related answer here.

( 2017-05-23 17:53:27 +0200 )edit

Sort by » oldest newest most voted

Hi

I do not reproduce you problem with ThisDatabaseDocument. You just have to connect as explained in this wiki page (in french, sorry but I hope that's understandable with the code and the sample database).

[EDIT]

The following syntaxes also work without problems in my environment:

sub PysOpen1
dim oConn as object, oForm as object
dim Prop(0) as New com.sun.star.beans.PropertyValue

Prop(0).Name = "ActiveConnection"
Prop(0).Value = oConn

dim FormName as String : FormName = "Form1"
end sub

sub PysOpen3
dim oConn as object, oForm as object
dim Prop(0) as New com.sun.star.beans.PropertyValue

Prop(0).Name = "ActiveConnection"
Prop(0).Value = oConn

dim FormName as String : FormName = "Form1"
end sub


Regards

more

ThisDatabaseDocument is always unavailable on my system Win7/LO 4.4.4 during the Open Document event, which led to the resort to ThisComponent I also am reading and writing across a network which might lead to higher latencies, which shouldn't matter, but might. This was one of the errors I had to work around. ThisComponent is only sometimes unavailable in the same circumstances.

( 2015-07-16 12:50:07 +0200 )edit

Presently, running MsgBox ThisDatabaseDocument.dbg_properties at the OpenDocument event in Linux LO 5.0.0.3 results in the error: BASIC runtime error. Object variable not set. So that solution does not work in this scenario.

( 2015-07-16 13:04:57 +0200 )edit

See my edit for another syntax. I do not have the problem by working through a network. However I can not test for now in Version 5 (and I'm on windows).

( 2015-07-16 13:21:43 +0200 )edit
1

The PysOpen1 does not work for me because it relies on ThisDatabaseDocument. PysOpen3 relies on ThisComponent and so does work, but I expect that repeated sufficiently on multiple systems I will occasionally encounter the problem that is the subject of the question. The workaround I am using is to Loop while testing InStr(ThisComponent.dbg_properties, "CurrentController") > 0. Sometimes it proceeds on the first loop, sometimes the second after an implicit Wait 15.

( 2015-07-16 16:09:20 +0200 )edit

@doug - FYI, I could test without problems with Version: 5.0.0.3 (windows 7/64). Moreover I had experimented with Mandriva - Debian (via network) when I wrote the Wiki FAQ. Well, anyway you have a workaround but it is strange... Regards

( 2015-07-17 17:58:09 +0200 )edit

Hi @doug - perhaps can you comment this tdf#92770 with your less restrictive steps to reproduce? Regards.

( 2015-07-23 14:11:05 +0200 )edit

I think I see what is going on, at least sometimes. In some startup situations, for example in Windows if you run on a link that directs RunMinimized the application window never gets the focus and for a Macro running on Open Document never gets the global populated. To work around I probably would need manually to set the focus through StarOffice global.

( 2015-08-07 16:09:43 +0200 )edit

Hello doug, another way to say ThisComponent would be:

StarDesktop.getCurrentComponent()

more