1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"TempVar" script:
language=
"StarBasic">REM =======================================================================================================================
4 REM === The Access2Base library is a part of the LibreOffice project. ===
5 REM === Full documentation is available on http://www.access2base.com ===
6 REM =======================================================================================================================
13 REM -----------------------------------------------------------------------------------------------------------------------
14 REM --- CLASS ROOT FIELDS ---
15 REM -----------------------------------------------------------------------------------------------------------------------
17 Private _Type As String
' Must be TEMPVAR
18 Private _Name As String
19 Private _Value As Variant
21 REM -----------------------------------------------------------------------------------------------------------------------
22 REM --- CONSTRUCTORS / DESTRUCTORS ---
23 REM -----------------------------------------------------------------------------------------------------------------------
24 Private Sub Class_Initialize()
28 End Sub
' Constructor
30 REM -----------------------------------------------------------------------------------------------------------------------
31 Private Sub Class_Terminate()
32 On Local Error Resume Next
33 Call Class_Initialize()
34 End Sub
' Destructor
36 REM -----------------------------------------------------------------------------------------------------------------------
38 Call Class_Terminate()
39 End Sub
' Explicit destructor
41 REM -----------------------------------------------------------------------------------------------------------------------
42 REM --- CLASS GET/LET/SET PROPERTIES ---
43 REM -----------------------------------------------------------------------------------------------------------------------
45 Property Get Name() As String
46 Name = _PropertyGet(
"Name
")
47 End Property
' Name (get)
49 REM -----------------------------------------------------------------------------------------------------------------------
50 Property Get ObjectType() As String
51 ObjectType = _PropertyGet(
"ObjectType
")
52 End Property
' ObjectType (get)
54 REM -----------------------------------------------------------------------------------------------------------------------
55 Property Get Value() As Variant
56 Value = _PropertyGet(
"Value
")
57 End Property
' Value (get)
59 Property Let Value(ByVal pvValue As Variant)
60 Call _PropertySet(
"Value
", pvValue)
61 End Property
' Value (set)
63 REM -----------------------------------------------------------------------------------------------------------------------
64 REM --- CLASS METHODS ---
65 REM -----------------------------------------------------------------------------------------------------------------------
67 Public Function getProperty(Optional ByVal pvProperty As Variant) As Variant
68 ' Return property value of psProperty property name
70 Utils._SetCalledSub(
"Property.getProperty
")
71 If IsMissing(pvProperty) Then Call _TraceArguments()
72 getProperty = _PropertyGet(pvProperty)
73 Utils._ResetCalledSub(
"Property.getProperty
")
75 End Function
' getProperty
77 REM -----------------------------------------------------------------------------------------------------------------------
78 Public Function hasProperty(ByVal Optional pvProperty As Variant) As Boolean
79 ' Return True if object has a valid property called pvProperty (case-insensitive comparison !)
81 If IsMissing(pvProperty) Then hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList()) Else hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList(), pvProperty)
84 End Function
' hasProperty
86 REM -----------------------------------------------------------------------------------------------------------------------
87 Public Function Properties(ByVal Optional pvIndex As Variant) As Variant
89 ' a Collection object if pvIndex absent
90 ' a Property object otherwise
92 Dim vProperty As Variant, vPropertiesList() As Variant, sObject As String
93 vPropertiesList = _PropertiesList()
94 sObject = Utils._PCase(_Type)
95 If IsMissing(pvIndex) Then
96 vProperty = PropertiesGet._Properties(sObject, _Name, vPropertiesList)
98 vProperty = PropertiesGet._Properties(sObject, _Name, vPropertiesList, pvIndex)
99 vProperty._Value = _PropertyGet(vPropertiesList(pvIndex))
103 Set Properties = vProperty
105 End Function
' Properties
107 REM -----------------------------------------------------------------------------------------------------------------------
108 Public Function setProperty(ByVal Optional psProperty As String, ByVal Optional pvValue As Variant) As Boolean
109 ' Return True if property setting OK
110 Dim cstThisSub As String
111 cstThisSub = Utils._PCase(_Type)
& ".getProperty
"
112 Utils._SetCalledSub(cstThisSub)
113 setProperty = _PropertySet(psProperty, pvValue)
114 Utils._ResetCalledSub(cstThisSub)
117 REM -----------------------------------------------------------------------------------------------------------------------
118 REM --- PRIVATE FUNCTIONS ---
119 REM -----------------------------------------------------------------------------------------------------------------------
120 Private Function _PropertiesList() As Variant
121 _PropertiesList = Array(
"Name
",
"ObjectType
",
"Value
")
122 End Function
' _PropertiesList
124 REM -----------------------------------------------------------------------------------------------------------------------
125 Private Function _PropertyGet(ByVal psProperty As String) As Variant
126 ' Return property value of the psProperty property name
128 If _ErrorHandler() Then On Local Error Goto Error_Function
129 Utils._SetCalledSub(
"TempVar.get
" & psProperty)
130 _PropertyGet = Nothing
132 Select Case UCase(psProperty)
133 Case UCase(
"Name
")
135 Case UCase(
"ObjectType
")
137 Case UCase(
"Value
")
138 _PropertyGet = _Value
144 Utils._ResetCalledSub(
"TempVar.get
" & psProperty)
147 TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(),
0,
1, psProperty)
148 _PropertyGet = Nothing
151 TraceError(TRACEABORT, Err,
"TempVar._PropertyGet
", Erl)
152 _PropertyGet = Nothing
154 End Function
' _PropertyGet
156 REM -----------------------------------------------------------------------------------------------------------------------
157 Private Function _PropertySet(ByVal psProperty As String, ByVal pvValue As Variant) As Boolean
159 Utils._SetCalledSub(
"TempVar.set
" & psProperty)
160 If _ErrorHandler() Then On Local Error Goto Error_Function
164 Dim iArgNr As Integer
166 If _IsLeft(_A2B_.CalledSub,
"TempVar.
") Then iArgNr =
1 Else iArgNr =
2
167 Select Case UCase(psProperty)
168 Case UCase(
"Value
")
170 _A2B_.TempVars.Item(UCase(_Name)).Value = pvValue
176 Utils._ResetCalledSub(
"TempVar.set
" & psProperty)
179 TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(),
0,
1, psProperty)
183 TraceError(TRACEFATAL, ERRPROPERTYVALUE, Utils._CalledSub(),
0,
1, Array(pvValue, psProperty))
187 TraceError(TRACEABORT, Err,
"TempVar._PropertySet
", Erl)
190 End Function
' _PropertySet