Difference between revisions of "Zh/Documentation/DevGuide/FirstSteps/Sequence"
From Apache OpenOffice Wiki
< Zh | Documentation
(New page: {{Documentation/DevGuide/FirstStepsTOC/Zh |FirstSteps2b=block |ShowPrevNext=block |PrevPage=Zh/Documentation/DevGuide/FirstSteps/Any |NextPage=Zh/Documentation/DevGuide/FirstSteps/Element ...) |
m |
||
Line 93: | Line 93: | ||
− | + | ||
− | [[Category:文档 | + | [[Category:文档/开发者指南/准备工作]] |
− | + | ||
− | + |
Revision as of 04:05, 11 June 2008
序列是一个 UNO 类型的值的同类集合,它具有可变数量的元素在最新的语言绑定中序列映射到数组。尽管 UNO 中的这些集合有时作为具有元素访问方法的对象实现(例如,通过 com.sun.star.container.XEnumeration 接口),但还是提供了序列类型,以便在远程性能相关的地方使用。
在 API 引用中通常使用尖括号来标注序列:
// a sequence of strings is notated as follows in the API reference sequence< string > aStringSequence;
在 Java 中,可将序列视为数组。(但请勿使用 null
来表示空序列,而是要使用通过 new
创建的零长度数组。)另外需要注意的是,创建 Java 对象的数组时仅创建引用数组,而不分配实际的对象。因此,必须使用 new
创建数组本身,然后对每个单独的对象需要再次使用 new
,并将新对象指定到数组。
PropertyValue
结构的空序列经常会用于 loadComponentFromURL
:
// create an empty array of PropertyValue structs for loadComponentFromURL PropertyValue[] emptyProps = new PropertyValue[0];
使用包含 loadComponentFromURL()
的加载参数时需要使用 PropertyValue
结构的序列。loadComponentFromURL()
和 com.sun.star.frame.XStorable 接口的可能参数值可以在服务
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);
在OpenOffice.org Basic中,一个简单 Dim
即可创建一个空数组。
'OpenOffice.org Basic Dim loadProps() 'empty array
结构序列是使用 new 和 Dim
创建的。
'OpenOffice.org Basic Dim loadProps(0) as new com.sun.star.beans.PropertyValue 'one PropertyValue
在 C++ 中,有一个用于序列的类模板。空序列可以通过省略所需的元素数来创建。
//C++ Sequence< ::com::sun::star::beans::PropertyValue > loadProperties; // empty sequence
如果传递多个元素,则可以获得所需长度的数组。
//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). |