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">
4 REM =======================================================================================================================
5 REM === The Access2Base library is a part of the LibreOffice project. ===
6 REM === Full documentation is available on http://www.access2base.com ===
7 REM =======================================================================================================================
14 REM -----------------------------------------------------------------------------------------------------------------------
15 REM --- CLASS ROOT FIELDS ---
16 REM -----------------------------------------------------------------------------------------------------------------------
18 Private _Type As String
' Must be TEMPVAR
19 Private _This As Object
' Workaround for absence of This builtin function
20 Private _Parent As Object
21 Private _Name As String
22 Private _Value As Variant
24 REM -----------------------------------------------------------------------------------------------------------------------
25 REM --- CONSTRUCTORS / DESTRUCTORS ---
26 REM -----------------------------------------------------------------------------------------------------------------------
27 Private Sub Class_Initialize()
33 End Sub
' Constructor
35 REM -----------------------------------------------------------------------------------------------------------------------
36 Private Sub Class_Terminate()
37 On Local Error Resume Next
38 Call Class_Initialize()
39 End Sub
' Destructor
41 REM -----------------------------------------------------------------------------------------------------------------------
43 Call Class_Terminate()
44 End Sub
' Explicit destructor
46 REM -----------------------------------------------------------------------------------------------------------------------
47 REM --- CLASS GET/LET/SET PROPERTIES ---
48 REM -----------------------------------------------------------------------------------------------------------------------
50 Property Get Name() As String
51 Name = _PropertyGet(
"Name
")
52 End Property
' Name (get)
54 REM -----------------------------------------------------------------------------------------------------------------------
55 Property Get ObjectType() As String
56 ObjectType = _PropertyGet(
"ObjectType
")
57 End Property
' ObjectType (get)
59 REM -----------------------------------------------------------------------------------------------------------------------
60 Property Get Value() As Variant
61 Value = _PropertyGet(
"Value
")
62 End Property
' Value (get)
64 Property Let Value(ByVal pvValue As Variant)
65 Call _PropertySet(
"Value
", pvValue)
66 End Property
' Value (set)
68 REM -----------------------------------------------------------------------------------------------------------------------
69 REM --- CLASS METHODS ---
70 REM -----------------------------------------------------------------------------------------------------------------------
72 Public Function getProperty(Optional ByVal pvProperty As Variant) As Variant
73 ' Return property value of psProperty property name
75 Utils._SetCalledSub(
"TempVar.getProperty
")
76 If IsMissing(pvProperty) Then Call _TraceArguments()
77 getProperty = _PropertyGet(pvProperty)
78 Utils._ResetCalledSub(
"TempVar.getProperty
")
80 End Function
' getProperty
82 REM -----------------------------------------------------------------------------------------------------------------------
83 Public Function hasProperty(ByVal Optional pvProperty As Variant) As Boolean
84 ' Return True if object has a valid property called pvProperty (case-insensitive comparison !)
86 If IsMissing(pvProperty) Then hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList()) Else hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList(), pvProperty)
89 End Function
' hasProperty
91 REM -----------------------------------------------------------------------------------------------------------------------
92 Public Function Properties(ByVal Optional pvIndex As Variant) As Variant
94 ' a Collection object if pvIndex absent
95 ' a Property object otherwise
97 Dim vProperty As Variant, vPropertiesList() As Variant, sObject As String
98 vPropertiesList = _PropertiesList()
99 sObject = Utils._PCase(_Type)
100 If IsMissing(pvIndex) Then
101 vProperty = PropertiesGet._Properties(sObject, _This, vPropertiesList)
103 vProperty = PropertiesGet._Properties(sObject, _This, vPropertiesList, pvIndex)
104 vProperty._Value = _PropertyGet(vPropertiesList(pvIndex))
108 Set Properties = vProperty
110 End Function
' Properties
112 REM -----------------------------------------------------------------------------------------------------------------------
113 Public Function setProperty(ByVal Optional psProperty As String, ByVal Optional pvValue As Variant) As Boolean
114 ' Return True if property setting OK
115 Utils._SetCalledSub(
"TempVar.getProperty
")
116 setProperty = _PropertySet(psProperty, pvValue)
117 Utils._ResetCalledSub(
"TempVar.getProperty
")
120 REM -----------------------------------------------------------------------------------------------------------------------
121 REM --- PRIVATE FUNCTIONS ---
122 REM -----------------------------------------------------------------------------------------------------------------------
123 Private Function _PropertiesList() As Variant
124 _PropertiesList = Array(
"Name
",
"ObjectType
",
"Value
")
125 End Function
' _PropertiesList
127 REM -----------------------------------------------------------------------------------------------------------------------
128 Private Function _PropertyGet(ByVal psProperty As String) As Variant
129 ' Return property value of the psProperty property name
131 If _ErrorHandler() Then On Local Error Goto Error_Function
132 Utils._SetCalledSub(
"TempVar.get
" & psProperty)
133 _PropertyGet = Nothing
135 Select Case UCase(psProperty)
136 Case UCase(
"Name
")
138 Case UCase(
"ObjectType
")
140 Case UCase(
"Value
")
141 _PropertyGet = _Value
147 Utils._ResetCalledSub(
"TempVar.get
" & psProperty)
150 TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(),
0,
1, psProperty)
151 _PropertyGet = Nothing
154 TraceError(TRACEABORT, Err,
"TempVar._PropertyGet
", Erl)
155 _PropertyGet = Nothing
157 End Function
' _PropertyGet
159 REM -----------------------------------------------------------------------------------------------------------------------
160 Private Function _PropertySet(ByVal psProperty As String, ByVal pvValue As Variant) As Boolean
162 Utils._SetCalledSub(
"TempVar.set
" & psProperty)
163 If _ErrorHandler() Then On Local Error Goto Error_Function
167 Dim iArgNr As Integer
169 If _IsLeft(_A2B_.CalledSub,
"TempVar.
") Then iArgNr =
1 Else iArgNr =
2
170 Select Case UCase(psProperty)
171 Case UCase(
"Value
")
173 _A2B_.TempVars.Item(UCase(_Name)).Value = pvValue
179 Utils._ResetCalledSub(
"TempVar.set
" & psProperty)
182 TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(),
0,
1, psProperty)
186 TraceError(TRACEFATAL, ERRPROPERTYVALUE, Utils._CalledSub(),
0,
1, Array(pvValue, psProperty))
190 TraceError(TRACEABORT, Err,
"TempVar._PropertySet
", Erl)
193 End Function
' _PropertySet