von viperbone » So, 24.01.2010 17:38
Hier noch zur Vollständigkeit ein kleines Beispielprogramm zum lesen und schreiben von Benutzerdefinierten Eigenschaften. Für Verbesserungsvorschläge bin ich offen:
Code: Alles auswählen
Sub Main
msgbox(SetDocProperty("myName", "viper"))
msgbox(GetDocProperty("myName"))
msgbox(SetDocProperty("myName", "bone"))
msgbox(GetDocProperty("myName"))
End Sub
Public Sub SetDocProperty(ByVal strVarName, ByVal aValue) as Boolean
Dim userProps As Object
Dim result as Boolean
result = false
On Error Goto ErrHandler
' get UserDefined Properties
userProps = thisComponent.DocumentProperties.getUserDefinedProperties()
' Try to Remove; on Error Property doesen't exists yet
If userProps.getPropertySetInfo().hasPropertyByName(strVarName) = False then
' http://api.openoffice.org/docs/common/ref/com/sun/star/beans/XPropertyContainer.html
userProps.addProperty(strVarName, ,aValue)
Else
' http://api.openoffice.org/docs/common/ref/com/sun/star/beans/XPropertySet.html
userProps.setPropertyValue(strVarName, aValue)
End If
result = true
ExitFunc:
SetDocProperty = result
Exit sub
ErrHandler:
Goto ExitFunc
End Sub
Public Sub GetDocProperty(ByVal strVarName) As String
Dim userProps As Object
On Error Resume Next
' get UserDefined Properties
userProps = thisComponent.DocumentProperties.getUserDefinedProperties()
' Try to Remove; on Error Property doesen't exists yet
If userProps.getPropertySetInfo().hasPropertyByName(strVarName) = True then
' http://api.openoffice.org/docs/common/ref/com/sun/star/beans/XPropertySet.html
GetDocProperty = userProps.getPropertyValue(strVarName)
Else
GetDocProperty = ""
End If
End Sub
Hier noch zur Vollständigkeit ein kleines Beispielprogramm zum lesen und schreiben von Benutzerdefinierten Eigenschaften. Für Verbesserungsvorschläge bin ich offen:
[code]
Sub Main
msgbox(SetDocProperty("myName", "viper"))
msgbox(GetDocProperty("myName"))
msgbox(SetDocProperty("myName", "bone"))
msgbox(GetDocProperty("myName"))
End Sub
Public Sub SetDocProperty(ByVal strVarName, ByVal aValue) as Boolean
Dim userProps As Object
Dim result as Boolean
result = false
On Error Goto ErrHandler
' get UserDefined Properties
userProps = thisComponent.DocumentProperties.getUserDefinedProperties()
' Try to Remove; on Error Property doesen't exists yet
If userProps.getPropertySetInfo().hasPropertyByName(strVarName) = False then
' http://api.openoffice.org/docs/common/ref/com/sun/star/beans/XPropertyContainer.html
userProps.addProperty(strVarName, ,aValue)
Else
' http://api.openoffice.org/docs/common/ref/com/sun/star/beans/XPropertySet.html
userProps.setPropertyValue(strVarName, aValue)
End If
result = true
ExitFunc:
SetDocProperty = result
Exit sub
ErrHandler:
Goto ExitFunc
End Sub
Public Sub GetDocProperty(ByVal strVarName) As String
Dim userProps As Object
On Error Resume Next
' get UserDefined Properties
userProps = thisComponent.DocumentProperties.getUserDefinedProperties()
' Try to Remove; on Error Property doesen't exists yet
If userProps.getPropertySetInfo().hasPropertyByName(strVarName) = True then
' http://api.openoffice.org/docs/common/ref/com/sun/star/beans/XPropertySet.html
GetDocProperty = userProps.getPropertyValue(strVarName)
Else
GetDocProperty = ""
End If
End Sub
[/code]