Ask Your Question
1

Base: another way to say ThisComponent?

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

doug gravatar image

updated 2015-07-16 04:24:46 +0200

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.

edit retag flag offensive close merge delete

Comments

Using LO 5.2.3.3 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 +0200 )edit

There is now a good related answer here.

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

2 Answers

Sort by » oldest newest most voted
1

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

pierre-yves samyn gravatar image

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

EasyTrieve gravatar image

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

edit flag offensive delete link more

Comments

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

doug gravatar imagedoug ( 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).

pierre-yves samyn gravatar imagepierre-yves samyn ( 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.

doug gravatar imagedoug ( 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

pierre-yves samyn gravatar imagepierre-yves samyn ( 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.

pierre-yves samyn gravatar imagepierre-yves samyn ( 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.

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

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

librebel gravatar image

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

Hello doug, another way to say ThisComponent would be:

StarDesktop.getCurrentComponent()
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

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

Seen: 910 times

Last updated: May 11 '17