Ask Your Question

Base: another way to say ThisComponent? [closed]

asked 2015-07-16 04:10:50 +0100

doug gravatar image

updated 2020-07-21 01:34:39 +0100

Alex Kemp gravatar image

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:

image description

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 or -- 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 flag offensive 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 I get the same problem: ThisDatabaseDocument is missing.

I have a follow up question here about this.

EasyTrieve gravatar imageEasyTrieve ( 2017-05-10 07:16:07 +0100 )edit

There is now a good related answer here.

EasyTrieve gravatar imageEasyTrieve ( 2017-05-23 17:53:27 +0100 )edit

2 Answers

Sort by » oldest newest most voted

answered 2015-07-16 09:11:07 +0100

pierre-yves samyn gravatar image

updated 2017-05-10 15:22:50 +0100

EasyTrieve gravatar image


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).


The following syntaxes also work without problems in my environment:

sub PysOpen1
  dim oConn as object, oForm as object
  dim Prop(0) as New

  dim UserName as String  : UserName = "foo"
  dim Password as String  : Password = "bar"
  oConn = ThisDatabaseDocument.DataSource.getConnection(UserName,Password) 

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

  dim FormName as String : FormName = "Form1"
 oForm=ThisDatabaseDocument.FormDocuments.loadComponentFromURL(FormName, "_blank", 0, Prop()) 
end sub

sub PysOpen3
  dim oConn as object, oForm as object
  dim Prop(0) as New

  dim UserName as String  : UserName = "foo"
  dim Password as String  : Password = "bar"
  oConn = ThisComponent.DataSource.getConnection(UserName,Password) 

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

  dim FormName as String : FormName = "Form1"
  oForm=ThisComponent.FormDocuments.loadComponentFromURL(FormName, "_blank", 0, Prop()) 
end sub


edit flag offensive delete link 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.

doug gravatar imagedoug ( 2015-07-16 12:50:07 +0100 )edit

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

doug gravatar imagedoug ( 2015-07-16 13:04:57 +0100 )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).

pierre-yves samyn gravatar imagepierre-yves samyn ( 2015-07-16 13:21:43 +0100 )edit

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.

doug gravatar imagedoug ( 2015-07-16 16:09:20 +0100 )edit

@doug - FYI, I could test without problems with Version: (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

pierre-yves samyn gravatar imagepierre-yves samyn ( 2015-07-17 17:58:09 +0100 )edit

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

pierre-yves samyn gravatar imagepierre-yves samyn ( 2015-07-23 14:11:05 +0100 )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.

doug gravatar imagedoug ( 2015-08-07 16:09:43 +0100 )edit

answered 2017-05-11 02:49:12 +0100

librebel gravatar image

updated 2017-05-11 05:42:11 +0100

Hello doug, another way to say ThisComponent would be:

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-07-16 04:10:50 +0100

Seen: 1,123 times

Last updated: May 11 '17