Difference between revisions of "Documentation/DevGuide/FirstSteps/Sequence"
m |
|||
(17 intermediate revisions by 8 users not shown) | |||
Line 1: | Line 1: | ||
− | {{Documentation/ | + | {{Documentation/DevGuide/FirstStepsTOC |
+ | |FirstSteps2b=block | ||
+ | |ShowPrevNext=block | ||
+ | |PrevPage=Documentation/DevGuide/FirstSteps/Any | ||
+ | |NextPage=Documentation/DevGuide/FirstSteps/Element Access | ||
+ | }} | ||
+ | {{Documentation/DevGuideLanguages|Documentation/DevGuide/FirstSteps/{{SUBPAGENAME}}}} | ||
{{DISPLAYTITLE:Sequence}} | {{DISPLAYTITLE:Sequence}} | ||
− | 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 | + | 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</idl> 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: |
+ | <syntaxhighlight lang="java"> | ||
// 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; | ||
+ | </syntaxhighlight> | ||
− | 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. | + | 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 <code>PropertyValue</code> structs is frequently needed for <code>loadComponentFromURL</code>: | An empty sequence of <code>PropertyValue</code> structs is frequently needed for <code>loadComponentFromURL</code>: | ||
+ | <syntaxhighlight lang="java"> | ||
// 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]; | ||
+ | </syntaxhighlight> | ||
− | |||
+ | |||
+ | <!-- Whitespace to move the next "source" block below the TOC. --> | ||
+ | |||
+ | 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 <idl>com.sun.star.frame.XStorable</idl> interface can be found in the service <idl>com.sun.star.document.MediaDescriptor</idl>. | ||
+ | |||
+ | |||
+ | <syntaxhighlight lang="java"> | ||
// 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 | ||
PropertyValue[] loadProps = new PropertyValue[1]; | PropertyValue[] loadProps = new PropertyValue[1]; | ||
Line 29: | Line 45: | ||
"file:///X:/share/samples/english/spreadsheets/OfficeSharingAssoc.sxc", | "file:///X:/share/samples/english/spreadsheets/OfficeSharingAssoc.sxc", | ||
"_blank", 0, loadProps); | "_blank", 0, loadProps); | ||
+ | </syntaxhighlight> | ||
− | In {{ | + | In {{AOo}} Basic, a simple <code>Dim</code> creates an empty array. |
− | ' | + | <syntaxhighlight lang="oobas"> |
+ | 'OpenOffice Basic | ||
Dim loadProps() 'empty array | Dim loadProps() 'empty array | ||
+ | </syntaxhighlight> | ||
A sequence of structs is created using new together with <code>Dim</code>. | A sequence of structs is created using new together with <code>Dim</code>. | ||
− | ' | + | <syntaxhighlight lang="oobas"> |
+ | 'OpenOffice Basic | ||
Dim loadProps(0) as new com.sun.star.beans.PropertyValue 'one PropertyValue | Dim loadProps(0) as new com.sun.star.beans.PropertyValue 'one PropertyValue | ||
+ | </syntaxhighlight> | ||
In C++, there is a class template for sequences. An empty sequence can be created by omitting the number of elements required. | In C++, there is a class template for sequences. An empty sequence can be created by omitting the number of elements required. | ||
+ | <syntaxhighlight lang="cpp"> | ||
//C++ | //C++ | ||
− | Sequence< ::com::sun::star::beans::PropertyValue > | + | Sequence< ::com::sun::star::beans::PropertyValue > loadProps; // empty sequence |
+ | </syntaxhighlight> | ||
If you pass a number of elements, you get an array of the requested length. | If you pass a number of elements, you get an array of the requested length. | ||
+ | <syntaxhighlight lang="cpp"> | ||
//C++ | //C++ | ||
Sequence< ::com::sun::star::beans::PropertyValue > loadProps( 1 ); | Sequence< ::com::sun::star::beans::PropertyValue > loadProps( 1 ); | ||
Line 58: | Line 82: | ||
0, | 0, | ||
loadProps); | loadProps); | ||
+ | </syntaxhighlight> | ||
{{PDL1}} | {{PDL1}} | ||
− | [[Category: First Steps]] | + | |
+ | [[Category:Documentation/Developer's Guide/First Steps]] |
Latest revision as of 16:01, 22 December 2020
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 Apache OpenOffice Basic, a simple Dim
creates an empty array.
'OpenOffice Basic Dim loadProps() 'empty array
A sequence of structs is created using new together with Dim
.
'OpenOffice 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 > loadProps; // 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);
Content on this page is licensed under the Public Documentation License (PDL). |