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

From Apache OpenOffice Wiki
Jump to: navigation, search
Line 1: Line 1:
{{DevGuide|Chapter1=block|Chapter1Level2b=block}}
+
{{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 [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 of strings is notated as follows in the API reference
 
   // a sequence of strings is notated as follows in the API reference

Revision as of 09:22, 16 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 [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 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 newfor 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 [IDL:com.sun.star.frame.XStorable] interface can be found in the service [IDL: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 [PRODUCTNAME] Basic, a simple Dim creates an empty array. '[PRODUCTNAME] Basic Dim loadProps() 'empty array A sequence of structs is created using new together with Dim. '[PRODUCTNAME] 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