Difference between revisions of "Documentation/DevGuide/FirstSteps/Sequence"

From Apache OpenOffice Wiki
Jump to: navigation, search
Line 1: Line 1:
 
{{DevGuide|FirstSteps=block|FirstSteps2b=block|PrevNext=block|Prev=Any|Next=Elements}}
 
{{DevGuide|FirstSteps=block|FirstSteps2b=block|PrevNext=block|Prev=Any|Next=Elements}}
A sequence is a homogeneous collection of values of one UNO type with a variable number of elements. Sequences map to arrays in most current language bindings. Although such collections are sometimes implemented as objects with element access methods in UNO (e.g., via the [IDL:com.sun.star.container.XEnumeration] interface), there is also the sequence type, to be used where remote performance matters. Sequences are always written with pointed brackets in the API reference:
+
A sequence is a homogeneous collection of values of one UNO type with a variable number of elements. Sequences map to arrays in most current language bindings. Although such collections are sometimes implemented as objects with element access methods in UNO (e.g., via the [http://api.openoffice.org/docs/common/ref/com/sun/star/container/XEnumeration.html com.sun.star.container.XEnumeration] interface), there is also the sequence type, to be used where remote performance matters. Sequences are always written with pointed brackets in the API reference:
  
 
   // a sequence of strings is notated as follows in the API reference
 
   // a sequence of strings is notated as follows in the API reference
 
   sequence< string > aStringSequence;
 
   sequence< string > aStringSequence;
  
In Java, you treat sequences as arrays. (But do not use null for empty sequences, use arrays created via new and with a length of zero instead.) Furthermore, keep in mind that you only create an array of references when creating an array of Java objects, the actual objects are not allocated. Therefore, you must use new to create the array itself, then you must again use newfor every single object and assign the new objects to the array.
+
In Java, you treat sequences as arrays. (But do not use <code>null</code> for empty sequences, use arrays created via <code>new</code> and with a length of zero instead.) Furthermore, keep in mind that you only create an array of references when creating an array of Java objects, the actual objects are not allocated. Therefore, you must use <code>new</code> to create the array itself, then you must again use <code>new</code> for every single object and assign the new objects to the array.
An empty sequence of PropertyValue structs is frequently needed for loadComponentFromURL:
+
An empty sequence of <code>PropertyValue</code> structs is frequently needed for <code>loadComponentFromURL</code>:
  
 
   // create an empty array of PropertyValue structs for loadComponentFromURL
 
   // create an empty array of PropertyValue structs for loadComponentFromURL
 
   PropertyValue[] emptyProps = new PropertyValue[0];
 
   PropertyValue[] emptyProps = new PropertyValue[0];
  
A sequence of PropertyValue structs is needed to use loading parameters with loadComponentFromURL(). The possible parameter values for loadComponentFromURL() and the [IDL:com.sun.star.frame.XStorable] interface can be found in the service [IDL:com.sun.star.document.MediaDescriptor].
+
A sequence of <code>PropertyValue</code> structs is needed to use loading parameters with <code>loadComponentFromURL()</code>. The possible parameter values for <code>loadComponentFromURL()</code> and the [http://api.openoffice.org/docs/common/ref/com/sun/star/frame/XStorable.html com.sun.star.frame.XStorable] interface can be found in the service [http://api.openoffice.org/docs/common/ref/com/sun/star/document/MediaDescriptor.html com.sun.star.document.MediaDescriptor].
  
 
   // create an array with one PropertyValue struct for loadComponentFromURL, it contains references only
 
   // create an array with one PropertyValue struct for loadComponentFromURL, it contains references only
Line 29: Line 29:
 
     "_blank", 0, loadProps);
 
     "_blank", 0, loadProps);
  
In {{PRODUCTNAME}} Basic, a simple Dim creates an empty array.
+
In {{PRODUCTNAME}} Basic, a simple <code>Dim</code> creates an empty array.
  
 
   '{{PRODUCTNAME}} Basic
 
   '{{PRODUCTNAME}} Basic
 
   Dim loadProps()  'empty array
 
   Dim loadProps()  'empty array
  
A sequence of structs is created using new together with Dim.
+
A sequence of structs is created using new together with <code>Dim</code>.
  
 
   '{{PRODUCTNAME}} Basic
 
   '{{PRODUCTNAME}} Basic

Revision as of 06:32, 21 May 2007

Template:DevGuide A sequence is a homogeneous collection of values of one UNO type with a variable number of elements. Sequences map to arrays in most current language bindings. Although such collections are sometimes implemented as objects with element access methods in UNO (e.g., via the com.sun.star.container.XEnumeration interface), there is also the sequence type, to be used where remote performance matters. Sequences are always written with pointed brackets in the API reference:

 // a sequence of strings is notated as follows in the API reference
 sequence< string > aStringSequence;

In Java, you treat sequences as arrays. (But do not use null for empty sequences, use arrays created via new and with a length of zero instead.) Furthermore, keep in mind that you only create an array of references when creating an array of Java objects, the actual objects are not allocated. Therefore, you must use new to create the array itself, then you must again use new for every single object and assign the new objects to the array. An empty sequence of PropertyValue structs is frequently needed for loadComponentFromURL:

 // create an empty array of PropertyValue structs for loadComponentFromURL
 PropertyValue[] emptyProps = new PropertyValue[0];

A sequence of PropertyValue structs is needed to use loading parameters with loadComponentFromURL(). The possible parameter values for loadComponentFromURL() and the com.sun.star.frame.XStorable interface can be found in the service com.sun.star.document.MediaDescriptor.

 // create an array with one PropertyValue struct for loadComponentFromURL, it contains references only
 PropertyValue[] loadProps = new PropertyValue[1];
 
 // instantiate PropertyValue struct and set its member fields
 PropertyValue asTemplate = new PropertyValue();
 asTemplate.Name = "AsTemplate";
 asTemplate.Value = Boolean.TRUE;
 
 // assign PropertyValue struct to first element in our array of references to PropertyValue structs
 loadProps[0] = asTemplate;
 
 // load calc file as template
 XComponent xSpreadsheetComponent = xComponentLoader.loadComponentFromURL(
   "file:///X:/share/samples/english/spreadsheets/OfficeSharingAssoc.sxc",
   "_blank", 0, loadProps);

In OpenOffice.org Basic, a simple Dim creates an empty array.

 'OpenOffice.org Basic
 Dim loadProps()  'empty array

A sequence of structs is created using new together with Dim.

 'OpenOffice.org Basic
 Dim loadProps(0) as new com.sun.star.beans.PropertyValue 'one PropertyValue

In C++, there is a class template for sequences. An empty sequence can be created by omitting the number of elements required.

 //C++
 Sequence< ::com::sun::star::beans::PropertyValue > loadProperties; // empty sequence

If you pass a number of elements, you get an array of the requested length.

 //C++
 Sequence< ::com::sun::star::beans::PropertyValue > loadProps( 1 );
 // the structs are default constructed
 loadProps[0].Name = OUString::createFromAscii( "AsTemplate" );
 loadProps[0].Handle <<= true;
 
 Reference< XComponent > rComponent = rComponentLoader->loadComponentFromURL(
 OUString::createFromAscii("private:factory/swriter"), 
 OUString::createFromAscii("_blank"), 
 0, 
 loadProps);
Personal tools