LibreOffice 7.1 Hjelp
A property, also called field or attribute, characterizes a given object or piece of information. Properties can be used to control access to data. It is common use to include instructions at setting or reading time of properties. Code can vary from simple assignment to complex context dependent routines. Using Get, Let or Set accessors enforces properties' consistency when necessary.
Dette uttrykket krev at Option Compatible vert sett framføre programkoden i ein modul.
[Private | Public] Property Get name[char | As typename]
End Property
[Private | Public] Property [Let | Set] name[char] [([Optional [ByRef | ByVal]]value[char | As typename])] [As typename]
End Property
namn: Namnet på eigenskapen.
argument: Verdi som skal overførast til rutinen Property.
Property brukar ofte eitt enkelt argument. Fleire argument kan likevel brukast samstundes.
Option Compatible
Sub Main
ProductName = "Office"
Print ProductName ' viser "LibreOffice"
End Sub
Private _office As String
Property Get ProductName As String
ProductName = _office
End Property
Property Let ProductName(value As String)
_office = "Libre"& value
End Property
Når eigenskapen Let eller Set manglar, hjelper Get til med å verna informasjon som ikkje må endrast av ein annan modul ved eit uhell.
Option Compatible
Public Property Get PathDelimiter As String ' Skriveverna variabel
Static this As String
If this = "" Then : Select Case GetGuiType()
Case 1 : this = ";" ' Windows
Case 4 : this = ":" ' Linux eller macOS
Case Else : Error 423 ' Eigenskap eller metode ikkje definert: PathDelimiter
End Select : End If
PathDelimiter = this
End Property ' skriveverna PathDelimiter
Sub Main
PathDelimiter = "a sentence" ' gjer ingenting
End Sub
Bruk Let eller Set når du handsamar UNO-tenester eller klasseobjekt:
Option Compatible
Sub Main
'Set anObject = CreateUnoService( "com.sun.star.frame.Desktop" )
anObject = CreateUnoService( "com.sun.star.frame.Desktop" )
Print anObject.SupportedServiceNames(0) ' displays "com.sun.star.frame.Frame"
End Sub
Property Get anObject As Object
Set anObject = _obj
End Property
Private _obj As Object
'Property Set anObject(value As Object)
'Set _obj = value.CurrentFrame
'End Property
Property Let anObject(value As Object)
Set _obj = value.CurrentFrame
End Property