21.08.2013 Views

OpenOffice.org BASIC Guide - OpenOffice.org wiki

OpenOffice.org BASIC Guide - OpenOffice.org wiki

OpenOffice.org BASIC Guide - OpenOffice.org wiki

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Overview of Central Interfaces<br />

basic object. The functions responsible are insertByName, removeByName and replaceByName.<br />

The following is a practical example of this. It calls a text document, which contains a StyleFamilies object<br />

and uses this to in turn make the paragraph templates (ParagraphStyles) of the document available.<br />

Dim StyleFamilies As Object<br />

Dim ParagraphStyles As Object<br />

Dim NewStyle As Object<br />

StyleFamilies = Textdoc.StyleFamilies<br />

ParagraphStyles = StyleFamilies.getByName("ParagraphStyles")<br />

ParagraphStyles.insertByName("NewStyle", NewStyle)<br />

ParagraphStyles.replaceByName("ChangingStyle", NewStyle)<br />

ParagraphStyles.removeByName("OldStyle")<br />

The insertByName line inserts the NewStyle style under the name of the same name in the ParagraphStyles<br />

object. The replaceByName line changes the object behind ChangingStyle into NewStyle. Finally, the<br />

removeByName call removes the object behind OldStyle from ParagraphStyles.<br />

Index-Based Access to Subordinate Objects<br />

The XIndexAccess and XIndexContainer interfaces are used in objects which contain subordinate objects and<br />

which can be addressed using an index.<br />

XIndexAccess provides the methods for accessing individual objects. XIndexContainer provides methods for<br />

inserting and removing elements.<br />

com.sun.star.container.XIndexAccess Interface<br />

XIndexAccess provides the getByIndex and getCount methods for calling the subordinate objects.<br />

getByIndex provides an object with a particular index. getCount returns how many objects are available.<br />

Dim Sheets As Object<br />

Dim Sheet As Object<br />

Dim I As Integer<br />

Sheets = Spreadsheet.Sheets<br />

For I = 0 to Sheets.getCount() - 1<br />

Sheet = Sheets.getByIndex(I)<br />

' Editing sheet<br />

Next I<br />

The example shows a loop that runs through all sheet elements one after another and saves a reference to each in<br />

the Sheet object variable. When working with the indexes, note that getCount returns the number of elements.<br />

The elements in getByIndex however are numbered beginning with 0. The counting variable of the loop<br />

therefore runs from 0 to getCount()-1.<br />

com.sun.star.container.XIndexContainer Interface<br />

The XIndexContainer interface provides the insertByIndex and removeByIndex functions. The parameters<br />

are structured in the same way as the corresponding functions in XNameContainer.<br />

Iterative Access to Subordinate Objects<br />

In some instances, an object may contain a list of subordinate objects that cannot be addressed by either a name<br />

or an index. In these situations, the XEnumeration and XenumerationAccess interfaces are appropriate. They<br />

provide a mechanism through which all subordinate elements of an objects can be passed, step by step, without<br />

having to use direct addressing.<br />

56 <strong>OpenOffice</strong>.<strong>org</strong> 3.2 <strong>BASIC</strong> <strong>Guide</strong> · March 2010

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!