使用 UNO 时所需的工具

From Apache OpenOffice Wiki
Jump to: navigation, search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
doc OOo
Book.png

现在的问题是哪些对象或服务(如果使用 UNO 术语)支持哪些属性、方法和接口以及如何确定这些情况。除了本指南以外,您还可以从以下来源获取有关对象的详细信息:supportsService 方法、调试方法、开发者指南和 API 参考。

supportsService 方法

很多 UNO 对象都支持 supportsService 方法,可以使用该方法来确定对象是否支持特定服务。例如,以下调用可确定 TextElement 对象是否支持 com.sun.star.text.Paragraph 服务。

Ok = TextElement.supportsService("com.sun.star.text.Paragraph")

调试属性

Apache OpenOffice Basic 中的每个 UNO 对象都知道已包含了哪些属性、方法和接口。它提供了以列表形式返回这些信息的属性。相应的属性有:

DBG_properties
返回一个字符串,其中包含某个对象的所有属性
DBG_methods
返回一个字符串,其中包含某个对象的所有方法
DBG_supportedInterfaces
返回一个字符串,其中包含支持某个对象的所有接口

以下程序代码说明了如何在实际应用程序中使用 DBG_propertiesDBG_methods。该代码首先创建 com.sun.star.frame.Desktop 服务,然后在消息框中显示支持的属性和方法。

Dim Obj As Object
Obj = createUnoService("com.sun.star.frame.Desktop")

MsgBox Obj.DBG_Properties
MsgBox Obj.DBG_methods

请注意,在使用 DBG_properties 时,该函数返回某个特定服务在理论上可以支持的所有属性。但不保证相关对象也可以使用这些属性。因此,在调用属性之前,必须使用 IsEmpty 函数检查该属性是否确实可用。

API 参考

有关可用服务及其接口、方法和属性的详细信息,请参见 Apache OpenOffice API 参考

Content on this page is licensed under the Public Documentation License (PDL).


Personal tools