Difference between revisions of "Documentation/BASIC Guide/Documents"

From Apache OpenOffice Wiki
Jump to: navigation, search
(Important note)
m (ThisComponent: "instruction" -> "object")
(2 intermediate revisions by 2 users not shown)
Line 11: Line 11:
  
 
* [[Documentation/BASIC Guide/StarDesktop|The StarDesktop]]
 
* [[Documentation/BASIC Guide/StarDesktop|The StarDesktop]]
* [[Documentation/BASIC Guide/Templates|Templates]]
+
* [[Documentation/BASIC Guide/Templates|Styles and Templates]]
  
=== Important note ===
+
=== The current document ===
In the next pages of the Basic Programming Guide you will see these instructions :
+
In previous versions of the Basic Programming Guide these instructions were used to obtain the current document :
 
<source lang="oobas">
 
<source lang="oobas">
 
Dim Doc As Object
 
Dim Doc As Object
Line 22: Line 22:
 
This correct code has a drawback : it does not work if the macro is started from the IDE because it then refers to the IDE, not the document. This code works only if the macro is started from the document itself!
 
This correct code has a drawback : it does not work if the macro is started from the IDE because it then refers to the IDE, not the document. This code works only if the macro is started from the document itself!
  
You should instead use Basic instruction <b>ThisComponent</b>. It refers to the document where the macro is run. <b>ThisComponent</b> will correspond to the document window immediately beneath the IDE window if you start the macro from the IDE.
+
You should instead use Basic object <b><tt>ThisComponent</tt></b>. It returns the document object on which the macro is run. If you start the macro from the IDE, <b><tt>ThisComponent</tt></b> will still find and return your document.
 
<source lang="oobas">
 
<source lang="oobas">
 
Dim Doc As Object
 
Dim Doc As Object

Revision as of 08:22, 24 January 2010


The Apache OpenOffice API has been structured so that as many of its parts as possible can be used universally for different tasks. This includes the interfaces and services for creating, opening, saving, converting, and printing documents and for template administration. Since these function areas are available in all types of documents, they are explained first in this chapter.

The current document

In previous versions of the Basic Programming Guide these instructions were used to obtain the current document :

Dim Doc As Object
 
Doc = StarDesktop.CurrentComponent

This correct code has a drawback : it does not work if the macro is started from the IDE because it then refers to the IDE, not the document. This code works only if the macro is started from the document itself!

You should instead use Basic object ThisComponent. It returns the document object on which the macro is run. If you start the macro from the IDE, ThisComponent will still find and return your document.

Dim Doc As Object
 
Doc = ThisComponent ' recommended coding for Basic


Content on this page is licensed under the Public Documentation License (PDL).
Personal tools