Base: another way to say ThisComponent?

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

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

I have a follow up question here about this.

There is now a good related answer here.

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

  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 com.sun.star.beans.PropertyValue

  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

Regards

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.

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.

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

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

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

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 Run Minimized 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.

Hello doug, another way to say ThisComponent would be:

StarDesktop.getCurrentComponent()