Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / wizards / source / sfdocuments / SF_Form.xba
blobcc7c2aecf34f087b2b57f1147b88fd1ac9a8045d
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="SF_Form" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
4 REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
5 REM === The SFDocuments library is one of the associated libraries. ===
6 REM === Full documentation is available on https://help.libreoffice.org/ ===
7 REM =======================================================================================================================
9 Option Compatible
10 Option ClassModule
12 Option Explicit
14 &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
15 &apos;&apos;&apos; SF_Form
16 &apos;&apos;&apos; =======
17 &apos;&apos;&apos; Management of forms defined in LibreOffice documents. Supported types are Base, Calc and Writer documents.
18 &apos;&apos;&apos; It includes the management of subforms
19 &apos;&apos;&apos; Each instance of the current class represents a single form or a single subform
20 &apos;&apos;&apos;
21 &apos;&apos;&apos; A form may optionally be (understand &quot;is often&quot;) linked to a data source manageable with the SFDatabases.Database service
22 &apos;&apos;&apos; The current service offers a rapid access to that service
23 &apos;&apos;&apos;
24 &apos;&apos;&apos; Definitions:
25 &apos;&apos;&apos;
26 &apos;&apos;&apos; FormDocument: BASE DOCUMENTS ONLY
27 &apos;&apos;&apos; For usual documents, there is only 1 forms container. It is either the document itself or one of its sheets (Calc)
28 &apos;&apos;&apos; A Base document may contain an unlimited number of form documents.
29 &apos;&apos;&apos; In the Base terminology they are called &quot;forms&quot; or &quot;Base forms&quot;. This could create some confusion.
30 &apos;&apos;&apos; They can be organized in folders. Their name is then always the full path of folders + form
31 &apos;&apos;&apos; with the slash (&quot;/&quot;) as path separator
32 &apos;&apos;&apos; A FormDocument is a set of Forms. Form names are visible in the user interface thanks to the form navigator
33 &apos;&apos;&apos; Often there is only 1 Form present in a FormDocument. Having more, however, might improve
34 &apos;&apos;&apos; the user experience significantly
35 &apos;&apos;&apos;
36 &apos;&apos;&apos; Form: WHERE IT IS ABOUT IN THE CURRENT &quot;Form&quot; SERVICE
37 &apos;&apos;&apos; Is an abstract set of Controls in an OPEN Document or FormDocument
38 &apos;&apos;&apos; Each form is usually linked to one single dataset (table, query or Select statement),
39 &apos;&apos;&apos; located in any database (provided the user may access it)
40 &apos;&apos;&apos; A usual document may contain several forms. Each of which may have its own data source (database + dataset)
41 &apos;&apos;&apos; A Base form document may contain several forms. Each of which may address its own dataset. The database however is unique
42 &apos;&apos;&apos; A form is defined by its owning Document or FormDocument and its FormName or FormIndex
43 &apos;&apos;&apos;
44 &apos;&apos;&apos; Service invocations:
45 &apos;&apos;&apos;
46 &apos;&apos;&apos; REM the form is stored in a Writer document
47 &apos;&apos;&apos; Dim oDoc As Object, myForm As Object
48 &apos;&apos;&apos; Set oDoc = CreateScriptService(&quot;SFDocuments.Document&quot;, ThisComponent)
49 &apos;&apos;&apos; Set myForm = oDoc.Forms(&quot;Form1&quot;)
50 &apos;&apos;&apos; &apos; or, alternatively, when there is only 1 form
51 &apos;&apos;&apos; Set myForm = oDoc.Forms(0)
52 &apos;&apos;&apos;
53 &apos;&apos;&apos; REM the form is stored in a Calc document
54 &apos;&apos;&apos; Dim oCalc As Object, myForm As Object
55 &apos;&apos;&apos; Set oCalc = CreateScriptService(&quot;SFDocuments.Document&quot;, ThisComponent)
56 &apos;&apos;&apos; Set myForm = oCalc.Forms(&quot;Sheet1&quot;, &quot;Form1&quot;)
57 &apos;&apos;&apos; &apos; or, alternatively, when there is only 1 form
58 &apos;&apos;&apos; Set myForm = oCalc.Forms(&quot;Sheet1&quot;, 0)
59 &apos;&apos;&apos;
60 &apos;&apos;&apos; REM the form is stored in one of the FormDocuments of a Base document
61 &apos;&apos;&apos; Dim oBase As Object, myFormDoc As Object, myForm As Object, mySubForm As Object
62 &apos;&apos;&apos; Set oBase = CreateScriptService(&quot;SFDocuments.Document&quot;, ThisDatabaseDocument)
63 &apos;&apos;&apos; Set oFormDoc = oBase.OpenFormDocument(&quot;thisFormDocument&quot;)
64 &apos;&apos;&apos; Set myForm = oFormDoc.Forms(&quot;MainForm&quot;)
65 &apos;&apos;&apos; &apos; or, alternatively, when there is only 1 form
66 &apos;&apos;&apos; Set myForm = oFormDoc.Forms(0)
67 &apos;&apos;&apos; &apos; To access a subform: myForm and mySubForm become distinct instances of the current class
68 &apos;&apos;&apos; Set mySubForm = myForm.SubForms(&quot;mySubForm&quot;)
69 &apos;&apos;&apos;
70 &apos;&apos;&apos; REM the form is the subject of an event
71 &apos;&apos;&apos; Sub OnEvent(ByRef poEvent As Object)
72 &apos;&apos;&apos; Dim myForm As Object
73 &apos;&apos;&apos; Set myForm = CreateScriptService(&quot;SFDocuments.FormEvent&quot;, poEvent)
74 &apos;&apos;&apos;
75 &apos;&apos;&apos; Detailed user documentation:
76 &apos;&apos;&apos; https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03/sf_form.html?DbPAR=BASIC
77 &apos;&apos;&apos;
78 &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
80 REM ================================================================== EXCEPTIONS
82 Private Const FORMDEADERROR = &quot;FORMDEADERROR&quot;
83 Private Const SUBFORMNOTFOUNDERROR = &quot;SUBFORMNOTFOUNDERROR&quot;
85 REM ============================================================= PRIVATE MEMBERS
87 Private [Me] As Object
88 Private [_Parent] As Object
89 Private ObjectType As String &apos; Must be Form
90 Private ServiceName As String
92 &apos; Form location
93 Private _Name As String &apos; Internal name of the form
94 Private _FormType As Integer &apos; One of the ISxxxFORM constants
95 Private _SheetName As String &apos; Name as the sheet containing the form (Calc only)
96 Private _FormDocumentName As String &apos; The hierarchical name of the containing form document (Base only)
97 Private _FormDocument As Object &apos; com.sun.star.comp.sdb.Content - the form document container
98 &apos; The form topmost containers
99 Private _Component As Object &apos; com.sun.star.lang.XComponent
100 Private _BaseComponent As Object &apos; com.sun.star.comp.dba.ODatabaseDocument
102 &apos; Events management
103 Private _CacheIndex As Long &apos; Index in central cache storage
105 &apos; Form UNO references
106 &apos; The entry to the interactions with the form. Validity checked by the _IsStillAlive() method
107 &apos; Each method or property requiring that the form is opened should first invoke that method
108 Private _Form As Object &apos; com.sun.star.form.XForm or com.sun.star.comp.forms.ODatabaseForm
110 &apos; Form attributes
111 Private _Database As Object &apos; Database class instance
113 &apos; Cache storage for controls
114 Private _ControlNames As Variant &apos; Array of control names
115 Private _ControlCache As Variant &apos; Array of control objects sorted like ElementNames of XForm
117 REM ============================================================ MODULE CONSTANTS
119 Const ISDOCFORM = 1 &apos; Form is stored in a Writer document
120 Const ISCALCFORM = 2 &apos; Form is stored in a Calc document
121 Const ISBASEFORM = 3 &apos; Form is stored in a Base form document
122 Const ISSUBFORM = 4 &apos; Form is a subform of a form or of another subform
123 Const ISUNDEFINED = -1 &apos; Undefined form type
125 REM ====================================================== CONSTRUCTOR/DESTRUCTOR
127 REM -----------------------------------------------------------------------------
128 Private Sub Class_Initialize()
129 Set [Me] = Nothing
130 Set [_Parent] = Nothing
131 ObjectType = &quot;FORM&quot;
132 ServiceName = &quot;SFDocuments.Form&quot;
133 _Name = &quot;&quot;
134 _SheetName = &quot;&quot;
135 _FormDocumentName = &quot;&quot;
136 Set _FormDocument = Nothing
137 Set _Component = Nothing
138 Set _BaseComponent = Nothing
139 _FormType = ISUNDEFINED
140 _CacheIndex = -1
141 Set _Form = Nothing
142 Set _Database = Nothing
143 _ControlNames = Array()
144 _ControlCache = Array()
145 End Sub &apos; SFDocuments.SF_Form Constructor
147 REM -----------------------------------------------------------------------------
148 Private Sub Class_Terminate()
149 Call Class_Initialize()
150 End Sub &apos; SFDocuments.SF_Form Destructor
152 REM -----------------------------------------------------------------------------
153 Public Function Dispose() As Variant
154 If Not IsNull(_Database) And (_FormType = ISDOCFORM Or _FormType = ISCALCFORM) Then
155 Set _Database = _Database.Dispose()
156 End If
157 SF_Register._CleanCacheEntry(_CacheIndex)
158 Call Class_Terminate()
159 Set Dispose = Nothing
160 End Function &apos; SFDocuments.SF_Form Explicit Destructor
162 REM ================================================================== PROPERTIES
164 REM -----------------------------------------------------------------------------
165 Property Get AllowDeletes() As Variant
166 &apos;&apos;&apos; The AllowDeletes property specifies if the form allows to delete records
167 AllowDeletes = _PropertyGet(&quot;AllowDeletes&quot;)
168 End Property &apos; SFDocuments.SF_Form.AllowDeletes (get)
170 REM -----------------------------------------------------------------------------
171 Property Let AllowDeletes(Optional ByVal pvAllowDeletes As Variant)
172 &apos;&apos;&apos; Set the updatable property AllowDeletes
173 _PropertySet(&quot;AllowDeletes&quot;, pvAllowDeletes)
174 End Property &apos; SFDocuments.SF_Form.AllowDeletes (let)
176 REM -----------------------------------------------------------------------------
177 Property Get AllowInserts() As Variant
178 &apos;&apos;&apos; The AllowInserts property specifies if the form allows to add records
179 AllowInserts = _PropertyGet(&quot;AllowInserts&quot;)
180 End Property &apos; SFDocuments.SF_Form.AllowInserts (get)
182 REM -----------------------------------------------------------------------------
183 Property Let AllowInserts(Optional ByVal pvAllowInserts As Variant)
184 &apos;&apos;&apos; Set the updatable property AllowInserts
185 _PropertySet(&quot;AllowInserts&quot;, pvAllowInserts)
186 End Property &apos; SFDocuments.SF_Form.AllowInserts (let)
188 REM -----------------------------------------------------------------------------
189 Property Get AllowUpdates() As Variant
190 &apos;&apos;&apos; The AllowUpdates property specifies if the form allows to update records
191 AllowUpdates = _PropertyGet(&quot;AllowUpdates&quot;)
192 End Property &apos; SFDocuments.SF_Form.AllowUpdates (get)
194 REM -----------------------------------------------------------------------------
195 Property Let AllowUpdates(Optional ByVal pvAllowUpdates As Variant)
196 &apos;&apos;&apos; Set the updatable property AllowUpdates
197 _PropertySet(&quot;AllowUpdates&quot;, pvAllowUpdates)
198 End Property &apos; SFDocuments.SF_Form.AllowUpdates (let)
200 REM -----------------------------------------------------------------------------
201 Property Get BaseForm() As String
202 &apos;&apos;&apos; The BaseForm property specifies the hierarchical name of the Base form containing the actual form
203 BaseForm = _PropertyGet(&quot;BaseForm&quot;)
204 End Property &apos; SFDocuments.SF_Form.BaseForm (get)
206 REM -----------------------------------------------------------------------------
207 Property Get Bookmark() As Variant
208 &apos;&apos;&apos; The Bookmark property specifies uniquely the current record of the form&apos;s underlying table, query or SQL statement.
209 Bookmark = _PropertyGet(&quot;Bookmark&quot;)
210 End Property &apos; SFDocuments.SF_Form.Bookmark (get)
212 REM -----------------------------------------------------------------------------
213 Property Let Bookmark(Optional ByVal pvBookmark As Variant)
214 &apos;&apos;&apos; Set the updatable property Bookmark
215 _PropertySet(&quot;Bookmark&quot;, pvBookmark)
216 End Property &apos; SFDocuments.SF_Form.Bookmark (let)
218 REM -----------------------------------------------------------------------------
219 Property Get CurrentRecord() As Variant
220 &apos;&apos;&apos; The CurrentRecord property identifies the current record in the recordset being viewed on a form
221 CurrentRecord = _PropertyGet(&quot;CurrentRecord&quot;)
222 End Property &apos; SFDocuments.SF_Form.CurrentRecord (get)
224 REM -----------------------------------------------------------------------------
225 Property Let CurrentRecord(Optional ByVal pvCurrentRecord As Variant)
226 &apos;&apos;&apos; Set the updatable property CurrentRecord
227 &apos;&apos;&apos; If the row number is positive, the cursor moves to the given row number with respect to the beginning of the result set.
228 &apos;&apos;&apos; The first row is row 1, the second is row 2, and so on.
229 &apos;&apos;&apos; If the given row number is negative, the cursor moves to an absolute row position with respect to the end of the result set.
230 &apos;&apos;&apos; For example, setting CurrentRecord = -1 positions the cursor on the last row, -2 indicates the next-to-last row, and so on
231 _PropertySet(&quot;CurrentRecord&quot;, pvCurrentRecord)
232 End Property &apos; SFDocuments.SF_Form.CurrentRecord (let)
234 REM -----------------------------------------------------------------------------
235 Property Get Filter() As Variant
236 &apos;&apos;&apos; The Filter property specifies a subset of records to be displayed.
237 Filter = _PropertyGet(&quot;Filter&quot;)
238 End Property &apos; SFDocuments.SF_Form.Filter (get)
240 REM -----------------------------------------------------------------------------
241 Property Let Filter(Optional ByVal pvFilter As Variant)
242 &apos;&apos;&apos; Set the updatable property Filter
243 _PropertySet(&quot;Filter&quot;, pvFilter)
244 End Property &apos; SFDocuments.SF_Form.Filter (let)
246 REM -----------------------------------------------------------------------------
247 Property Get LinkChildFields() As Variant
248 &apos;&apos;&apos; The LinkChildFields property specifies how records in a subform (child) are linked to records in its parent form
249 &apos;&apos;&apos; It returns an array of strings
250 LinkChildFields = _PropertyGet(&quot;LinkChildFields&quot;)
251 End Property &apos; SFDocuments.SF_Form.LinkChildFields (get)
253 REM -----------------------------------------------------------------------------
254 Property Get LinkParentFields() As Variant
255 &apos;&apos;&apos; The LinkParentFields property specifies how records in a subform (Child) are linked to records in its parent form
256 &apos;&apos;&apos; It returns an array of strings
257 LinkParentFields = _PropertyGet(&quot;LinkParentFields&quot;)
258 End Property &apos; SFDocuments.SF_Form.LinkParentFields (get)
260 REM -----------------------------------------------------------------------------
261 Property Get Name() As String
262 &apos;&apos;&apos; Return the name of the actual Form
263 Name = _PropertyGet(&quot;Name&quot;)
264 End Property &apos; SFDocuments.SF_Form.Name
266 REM -----------------------------------------------------------------------------
267 Property Get OnApproveCursorMove() As Variant
268 &apos;&apos;&apos; The OnApproveCursorMove property specifies the script to trigger when this event occurs
269 OnApproveCursorMove = _PropertyGet(&quot;OnApproveCursorMove&quot;)
270 End Property &apos; SFDocuments.SF_Form.OnApproveCursorMove (get)
272 REM -----------------------------------------------------------------------------
273 Property Let OnApproveCursorMove(Optional ByVal pvOnApproveCursorMove As Variant)
274 &apos;&apos;&apos; Set the updatable property OnApproveCursorMove
275 _PropertySet(&quot;OnApproveCursorMove&quot;, pvOnApproveCursorMove)
276 End Property &apos; SFDocuments.SF_Form.OnApproveCursorMove (let)
278 REM -----------------------------------------------------------------------------
279 Property Get OnApproveReset() As Variant
280 &apos;&apos;&apos; The OnApproveReset property specifies the script to trigger when this event occurs
281 OnApproveReset = _PropertyGet(&quot;OnApproveReset&quot;)
282 End Property &apos; SFDocuments.SF_Form.OnApproveReset (get)
284 REM -----------------------------------------------------------------------------
285 Property Let OnApproveReset(Optional ByVal pvOnApproveReset As Variant)
286 &apos;&apos;&apos; Set the updatable property OnApproveReset
287 _PropertySet(&quot;OnApproveReset&quot;, pvOnApproveReset)
288 End Property &apos; SFDocuments.SF_Form.OnApproveReset (let)
290 REM -----------------------------------------------------------------------------
291 Property Get OnApproveRowChange() As Variant
292 &apos;&apos;&apos; The OnApproveRowChange property specifies the script to trigger when this event occurs
293 OnApproveRowChange = _PropertyGet(&quot;OnApproveRowChange&quot;)
294 End Property &apos; SFDocuments.SF_Form.OnApproveRowChange (get)
296 REM -----------------------------------------------------------------------------
297 Property Let OnApproveRowChange(Optional ByVal pvOnApproveRowChange As Variant)
298 &apos;&apos;&apos; Set the updatable property OnApproveRowChange
299 _PropertySet(&quot;OnApproveRowChange&quot;, pvOnApproveRowChange)
300 End Property &apos; SFDocuments.SF_Form.OnApproveRowChange (let)
302 REM -----------------------------------------------------------------------------
303 Property Get OnApproveSubmit() As Variant
304 &apos;&apos;&apos; The OnApproveSubmit property specifies the script to trigger when this event occurs
305 OnApproveSubmit = _PropertyGet(&quot;OnApproveSubmit&quot;)
306 End Property &apos; SFDocuments.SF_Form.OnApproveSubmit (get)
308 REM -----------------------------------------------------------------------------
309 Property Let OnApproveSubmit(Optional ByVal pvOnApproveSubmit As Variant)
310 &apos;&apos;&apos; Set the updatable property OnApproveSubmit
311 _PropertySet(&quot;OnApproveSubmit&quot;, pvOnApproveSubmit)
312 End Property &apos; SFDocuments.SF_Form.OnApproveSubmit (let)
314 REM -----------------------------------------------------------------------------
315 Property Get OnConfirmDelete() As Variant
316 &apos;&apos;&apos; The OnConfirmDelete property specifies the script to trigger when this event occurs
317 OnConfirmDelete = _PropertyGet(&quot;OnConfirmDelete&quot;)
318 End Property &apos; SFDocuments.SF_Form.OnConfirmDelete (get)
320 REM -----------------------------------------------------------------------------
321 Property Let OnConfirmDelete(Optional ByVal pvOnConfirmDelete As Variant)
322 &apos;&apos;&apos; Set the updatable property OnConfirmDelete
323 _PropertySet(&quot;OnConfirmDelete&quot;, pvOnConfirmDelete)
324 End Property &apos; SFDocuments.SF_Form.OnConfirmDelete (let)
326 REM -----------------------------------------------------------------------------
327 Property Get OnCursorMoved() As Variant
328 &apos;&apos;&apos; The OnCursorMoved property specifies the script to trigger when this event occurs
329 OnCursorMoved = _PropertyGet(&quot;OnCursorMoved&quot;)
330 End Property &apos; SFDocuments.SF_Form.OnCursorMoved (get)
332 REM -----------------------------------------------------------------------------
333 Property Let OnCursorMoved(Optional ByVal pvOnCursorMoved As Variant)
334 &apos;&apos;&apos; Set the updatable property OnCursorMoved
335 _PropertySet(&quot;OnCursorMoved&quot;, pvOnCursorMoved)
336 End Property &apos; SFDocuments.SF_Form.OnCursorMoved (let)
338 REM -----------------------------------------------------------------------------
339 Property Get OnErrorOccurred() As Variant
340 &apos;&apos;&apos; The OnErrorOccurred property specifies the script to trigger when this event occurs
341 OnErrorOccurred = _PropertyGet(&quot;OnErrorOccurred&quot;)
342 End Property &apos; SFDocuments.SF_Form.OnErrorOccurred (get)
344 REM -----------------------------------------------------------------------------
345 Property Let OnErrorOccurred(Optional ByVal pvOnErrorOccurred As Variant)
346 &apos;&apos;&apos; Set the updatable property OnErrorOccurred
347 _PropertySet(&quot;OnErrorOccurred&quot;, pvOnErrorOccurred)
348 End Property &apos; SFDocuments.SF_Form.OnErrorOccurred (let)
350 REM -----------------------------------------------------------------------------
351 Property Get OnLoaded() As Variant
352 &apos;&apos;&apos; The OnLoaded property specifies the script to trigger when this event occurs
353 OnLoaded = _PropertyGet(&quot;OnLoaded&quot;)
354 End Property &apos; SFDocuments.SF_Form.OnLoaded (get)
356 REM -----------------------------------------------------------------------------
357 Property Let OnLoaded(Optional ByVal pvOnLoaded As Variant)
358 &apos;&apos;&apos; Set the updatable property OnLoaded
359 _PropertySet(&quot;OnLoaded&quot;, pvOnLoaded)
360 End Property &apos; SFDocuments.SF_Form.OnLoaded (let)
362 REM -----------------------------------------------------------------------------
363 Property Get OnReloaded() As Variant
364 &apos;&apos;&apos; The OnReloaded property specifies the script to trigger when this event occurs
365 OnReloaded = _PropertyGet(&quot;OnReloaded&quot;)
366 End Property &apos; SFDocuments.SF_Form.OnReloaded (get)
368 REM -----------------------------------------------------------------------------
369 Property Let OnReloaded(Optional ByVal pvOnReloaded As Variant)
370 &apos;&apos;&apos; Set the updatable property OnReloaded
371 _PropertySet(&quot;OnReloaded&quot;, pvOnReloaded)
372 End Property &apos; SFDocuments.SF_Form.OnReloaded (let)
374 REM -----------------------------------------------------------------------------
375 Property Get OnReloading() As Variant
376 &apos;&apos;&apos; The OnReloading property specifies the script to trigger when this event occurs
377 OnReloading = _PropertyGet(&quot;OnReloading&quot;)
378 End Property &apos; SFDocuments.SF_Form.OnReloading (get)
380 REM -----------------------------------------------------------------------------
381 Property Let OnReloading(Optional ByVal pvOnReloading As Variant)
382 &apos;&apos;&apos; Set the updatable property OnReloading
383 _PropertySet(&quot;OnReloading&quot;, pvOnReloading)
384 End Property &apos; SFDocuments.SF_Form.OnReloading (let)
386 REM -----------------------------------------------------------------------------
387 Property Get OnResetted() As Variant
388 &apos;&apos;&apos; The OnResetted property specifies the script to trigger when this event occurs
389 OnResetted = _PropertyGet(&quot;OnResetted&quot;)
390 End Property &apos; SFDocuments.SF_Form.OnResetted (get)
392 REM -----------------------------------------------------------------------------
393 Property Let OnResetted(Optional ByVal pvOnResetted As Variant)
394 &apos;&apos;&apos; Set the updatable property OnResetted
395 _PropertySet(&quot;OnResetted&quot;, pvOnResetted)
396 End Property &apos; SFDocuments.SF_Form.OnResetted (let)
398 REM -----------------------------------------------------------------------------
399 Property Get OnRowChanged() As Variant
400 &apos;&apos;&apos; The OnRowChanged property specifies the script to trigger when this event occurs
401 OnRowChanged = _PropertyGet(&quot;OnRowChanged&quot;)
402 End Property &apos; SFDocuments.SF_Form.OnRowChanged (get)
404 REM -----------------------------------------------------------------------------
405 Property Let OnRowChanged(Optional ByVal pvOnRowChanged As Variant)
406 &apos;&apos;&apos; Set the updatable property OnRowChanged
407 _PropertySet(&quot;OnRowChanged&quot;, pvOnRowChanged)
408 End Property &apos; SFDocuments.SF_Form.OnRowChanged (let)
410 REM -----------------------------------------------------------------------------
411 Property Get OnUnloaded() As Variant
412 &apos;&apos;&apos; The OnUnloaded property specifies the script to trigger when this event occurs
413 OnUnloaded = _PropertyGet(&quot;OnUnloaded&quot;)
414 End Property &apos; SFDocuments.SF_Form.OnUnloaded (get)
416 REM -----------------------------------------------------------------------------
417 Property Let OnUnloaded(Optional ByVal pvOnUnloaded As Variant)
418 &apos;&apos;&apos; Set the updatable property OnUnloaded
419 _PropertySet(&quot;OnUnloaded&quot;, pvOnUnloaded)
420 End Property &apos; SFDocuments.SF_Form.OnUnloaded (let)
422 REM -----------------------------------------------------------------------------
423 Property Get OnUnloading() As Variant
424 &apos;&apos;&apos; The OnUnloading property specifies the script to trigger when this event occurs
425 OnUnloading = _PropertyGet(&quot;OnUnloading&quot;)
426 End Property &apos; SFDocuments.SF_Form.OnUnloading (get)
428 REM -----------------------------------------------------------------------------
429 Property Let OnUnloading(Optional ByVal pvOnUnloading As Variant)
430 &apos;&apos;&apos; Set the updatable property OnUnloading
431 _PropertySet(&quot;OnUnloading&quot;, pvOnUnloading)
432 End Property &apos; SFDocuments.SF_Form.OnUnloading (let)
434 REM -----------------------------------------------------------------------------
435 Property Get OrderBy() As Variant
436 &apos;&apos;&apos; The OrderBy property specifies in which order the records should be displayed.
437 OrderBy = _PropertyGet(&quot;OrderBy&quot;)
438 End Property &apos; SFDocuments.SF_Form.OrderBy (get)
440 REM -----------------------------------------------------------------------------
441 Property Let OrderBy(Optional ByVal pvOrderBy As Variant)
442 &apos;&apos;&apos; Set the updatable property OrderBy
443 _PropertySet(&quot;OrderBy&quot;, pvOrderBy)
444 End Property &apos; SFDocuments.SF_Form.OrderBy (let)
446 REM -----------------------------------------------------------------------------
447 Property Get Parent() As Object
448 &apos;&apos;&apos; Return the Parent of the actual Form
449 Parent = _PropertyGet(&quot;Parent&quot;)
450 End Property &apos; SFDocuments.SF_Form.Parent
452 REM -----------------------------------------------------------------------------
453 Property Get RecordSource() As Variant
454 &apos;&apos;&apos; The RecordSource property specifies the source of the data,
455 &apos;&apos;&apos; a table name, a query name or a SQL statement
456 RecordSource = _PropertyGet(&quot;RecordSource&quot;)
457 End Property &apos; SFDocuments.SF_Form.RecordSource (get)
459 REM -----------------------------------------------------------------------------
460 Property Let RecordSource(Optional ByVal pvRecordSource As Variant)
461 &apos;&apos;&apos; Set the updatable property RecordSource
462 _PropertySet(&quot;RecordSource&quot;, pvRecordSource)
463 End Property &apos; SFDocuments.SF_Form.RecordSource (let)
465 REM -----------------------------------------------------------------------------
466 Property Get XForm() As Object
467 &apos;&apos;&apos; The XForm property returns the XForm UNO object of the Form
468 XForm = _PropertyGet(&quot;XForm&quot;)
469 End Property &apos; SFDocuments.SF_Form.XForm (get)
471 REM ===================================================================== METHODS
473 REM -----------------------------------------------------------------------------
474 Public Function Activate() As Boolean
475 &apos;&apos;&apos; Set the focus on the current Form instance
476 &apos;&apos;&apos; Probably called from after an event occurrence or to focus on an open Base form document
477 &apos;&apos;&apos; If the parent document is ...
478 &apos;&apos;&apos; Calc Activate the corresponding sheet
479 &apos;&apos;&apos; Writer Activate the parent document
480 &apos;&apos;&apos; Base Activate the parent form document
481 &apos;&apos;&apos; Args:
482 &apos;&apos;&apos; Returns:
483 &apos;&apos;&apos; True if focusing is successful
484 &apos;&apos;&apos; Example:
485 &apos;&apos;&apos; myForm.Activate()
487 Dim bActivate As Boolean &apos; Return value
488 Dim oContainer As Object &apos; com.sun.star.awt.XWindow
489 Const cstThisSub = &quot;SFDocuments.Form.Activate&quot;
490 Const cstSubArgs = &quot;&quot;
492 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
493 bActivate = False
495 Check:
496 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
497 If Not _IsStillAlive() Then GoTo Finally
498 End If
499 Try:
500 Select Case _FormType
501 Case ISDOCFORM : bActivate = [_Parent].Activate()
502 Case ISCALCFORM : bActivate = [_Parent].Activate(_SheetName)
503 Case ISBASEFORM
504 Set oContainer = _FormDocument.Component.CurrentController.Frame.ContainerWindow
505 With oContainer
506 If .isVisible() = False Then .setVisible(True)
507 .IsMinimized = False
508 .setFocus()
509 .toFront() &apos; Force window change in Linux
510 Wait 1 &apos; Bypass desynchro issue in Linux
511 End With
512 bActivate = True
513 End Select
515 Finally:
516 Activate = bActivate
517 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
518 Exit Function
519 Catch:
520 GoTo Finally
521 End Function &apos; SFDocuments.SF_Form.Activate
523 REM -----------------------------------------------------------------------------
524 Public Function CloseFormDocument() As Boolean
525 &apos;&apos;&apos; Close the form document containing the actual form instance
526 &apos;&apos;&apos; The form instance is disposed
527 &apos;&apos;&apos; The method does nothing if the actual form is not located in a Base form document
528 &apos;&apos;&apos; Args:
529 &apos;&apos;&apos; Returns:
530 &apos;&apos;&apos; True if closure is successful
531 &apos;&apos;&apos; Example:
532 &apos;&apos;&apos; myForm.CloseFormDocument()
534 Dim bClose As Boolean &apos; Return value
535 Dim oContainer As Object &apos; com.sun.star.awt.XWindow
536 Const cstThisSub = &quot;SFDocuments.Form.CloseFormDocument&quot;
537 Const cstSubArgs = &quot;&quot;
539 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
540 bClose = False
542 Check:
543 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
544 If Not _IsStillAlive() Then GoTo Finally
545 End If
546 Try:
547 Select Case _FormType
548 Case ISDOCFORM, ISCALCFORM
549 Case ISBASEFORM, ISSUBFORM
550 If Not IsNull(_FormDocument) Then
551 _FormDocument.close()
552 Dispose()
553 bClose = True
554 End If
555 Case Else
556 End Select
558 Finally:
559 CloseFormDocument = bClose
560 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
561 Exit Function
562 Catch:
563 GoTo Finally
564 End Function &apos; SFDocuments.SF_Form.CloseFormDocument
566 REM -----------------------------------------------------------------------------
567 Public Function Controls(Optional ByVal ControlName As Variant) As Variant
568 &apos;&apos;&apos; Return either
569 &apos;&apos;&apos; - the list of the controls contained in the Form
570 &apos;&apos;&apos; - a Form control object based on its name
571 &apos;&apos;&apos; Args:
572 &apos;&apos;&apos; ControlName: a valid control name as a case-sensitive string. If absent the list is returned
573 &apos;&apos;&apos; Returns:
574 &apos;&apos;&apos; A zero-base array of strings if ControlName is absent
575 &apos;&apos;&apos; An instance of the SF_FormControl class if ControlName exists
576 &apos;&apos;&apos; Exceptions:
577 &apos;&apos;&apos; ControlName is invalid
578 &apos;&apos;&apos; Example:
579 &apos;&apos;&apos; Dim myForm As Object, myList As Variant, myControl As Object
580 &apos;&apos;&apos; Set myForm = myDoc.Forms(&quot;myForm&quot;)
581 &apos;&apos;&apos; myList = myForm.Controls()
582 &apos;&apos;&apos; Set myControl = myForm.Controls(&quot;myTextBox&quot;)
584 Dim oControl As Object &apos; The new control class instance
585 Dim lIndexOfNames As Long &apos; Index in ElementNames array. Used to access _ControlCache
586 Dim vControl As Variant &apos; Alias of _ControlCache entry
587 Dim i As Long
588 Const cstThisSub = &quot;SFDocuments.Form.Controls&quot;
589 Const cstSubArgs = &quot;[ControlName]&quot;
591 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
593 Check:
594 If IsMissing(ControlName) Or IsEmpty(ControlName) Then ControlName = &quot;&quot;
595 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
596 If Not _IsStillAlive() Then GoTo Finally
597 If Not ScriptForge.SF_Utils._Validate(ControlName, &quot;ControlName&quot;, V_STRING) Then GoTo Finally
598 End If
600 Try:
601 &apos; Collect all control names if not yet done
602 If UBound(_ControlNames) &lt; 0 Then
603 _ControlNames = _Form.getElementNames()
604 &apos; Remove all subforms from the list
605 For i = 0 To UBound(_ControlNames)
606 &apos; Subforms have no ClassId property
607 If Not ScriptForge.SF_Session.HasUnoProperty(_Form.getByName(_ControlNames(i)), &quot;ClassId&quot;) Then _ControlNames(i) = &quot;&quot;
608 Next i
609 _ControlNames = ScriptForge.SF_Array.TrimArray(_ControlNames)
610 &apos; Size the cache accordingly
611 If UBound(_ControlNames) &gt;= 0 Then
612 ReDim _ControlCache(0 To UBound(_ControlNames))
613 End If
614 End If
616 &apos; Return the list of controls or a FormControl instance
617 If Len(ControlName) = 0 Then
618 Controls = _ControlNames
620 Else
622 If Not _Form.hasByName(ControlName) Then GoTo CatchNotFound
623 lIndexOfNames = ScriptForge.SF_Array.IndexOf(_ControlNames, ControlName, CaseSensitive := True)
624 &apos; Reuse cache when relevant
625 vControl = _ControlCache(lIndexOfNames)
627 If IsEmpty(vControl) Then
628 &apos; Create the new form control class instance
629 Set oControl = New SF_FormControl
630 With oControl
631 ._Name = ControlName
632 Set .[Me] = oControl
633 Set .[_Parent] = [Me]
634 Set ._ParentForm = [Me]
635 ._IndexOfNames = lIndexOfNames
636 ._FormName = _Name
637 &apos; Get model and view of the current control
638 Set ._ControlModel = _Form.getByName(ControlName)
639 ._Initialize()
640 End With
641 Else
642 Set oControl = vControl
643 End If
645 Set Controls = oControl
646 End If
648 Finally:
649 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
650 Exit Function
651 Catch:
652 GoTo Finally
653 CatchNotFound:
654 ScriptForge.SF_Utils._Validate(ControlName, &quot;ControlName&quot;, V_STRING, _Form.getElementNames())
655 GoTo Finally
656 End Function &apos; SFDocuments.SF_Form.Controls
658 REM -----------------------------------------------------------------------------
659 Public Function GetDatabase(Optional ByVal User As Variant _
660 , Optional ByVal Password As Variant _
661 ) As Object
662 &apos;&apos;&apos; Returns a Database instance (service = SFDatabases.Database) giving access
663 &apos;&apos;&apos; to the execution of SQL commands on the database defined and/or stored in
664 &apos;&apos;&apos; the actual Base document
665 &apos;&apos;&apos; Each main form has its own database connection, except within Base documents where
666 &apos;&apos;&apos; they all share the same connection
667 &apos;&apos;&apos; Args:
668 &apos;&apos;&apos; User, Password: the login parameters as strings. Defaults = &quot;&quot;
669 &apos;&apos;&apos; Returns:
670 &apos;&apos;&apos; A SFDatabases.Database instance or Nothing
671 &apos;&apos;&apos; Example:
672 &apos;&apos;&apos; Dim myDb As Object
673 &apos;&apos;&apos; Set myDb = oForm.GetDatabase()
675 Dim FSO As Object &apos; Alias for SF_FileSystem
676 Dim sDataSource As String &apos; Database file name in FileNaming format
677 Dim sUser As String &apos; Alias for User
678 Dim sPassword As String &apos; Alias for Password
679 Const cstThisSub = &quot;SFDocuments.Form.GetDatabase&quot;
680 Const cstSubArgs = &quot;[User=&quot;&quot;&quot;&quot;], [Password=&quot;&quot;&quot;&quot;]&quot;
682 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
683 Set GetDatabase = Nothing
685 Check:
686 If IsMissing(User) Or IsEmpty(User) Then User = &quot;&quot;
687 If IsMissing(Password) Or IsEmpty(Password) Then Password = &quot;&quot;
688 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
689 If Not [_Parent]._IsStillAlive(False) Then GoTo Finally
690 If Not ScriptForge.SF_Utils._Validate(User, &quot;User&quot;, V_STRING) Then GoTo Finally
691 If Not ScriptForge.SF_Utils._Validate(Password, &quot;Password&quot;, V_STRING) Then GoTo Finally
692 End If
694 Try:
695 &apos; Adjust connection arguments
696 If Len(User) = 0 Then
697 If ScriptForge.SF_Session.HasUnoProperty(_Form, &quot;User&quot;) Then sUser = _Form.User Else sUser = &quot;&quot;
698 Else
699 sUser = User
700 End If
701 If Len(sUser) + Len(Password) = 0 Then
702 If ScriptForge.SF_Session.HasUnoProperty(_Form, &quot;Password&quot;) Then sPassword = _Form.Password Else sPassword = Password
703 End If
705 &apos; Connect to database, avoiding multiple requests
706 If IsNull(_Database) Then &apos; 1st connection request from the current form instance
707 If _FormType = ISBASEFORM And Not IsNull(_BaseComponent) Then
708 &apos; Fetch the shared connection
709 Set _Database = [_Parent].GetDatabase(User, Password)
710 ElseIf _FormType = ISSUBFORM Then
711 Set _Database = [_Parent].GetDatabase() &apos; Recursive call, climb the tree
712 ElseIf Len(_Form.DataSourceName) = 0 Then &apos; There is no database linked with the form
713 &apos; Return Nothing
714 Else
715 &apos; Check if DataSourceName is a file or a registered name and create database instance accordingly
716 Set FSO = ScriptForge.SF_FileSystem
717 sDataSource = FSO._ConvertFromUrl(_Form.DataSourceName)
718 If FSO.FileExists(sDataSource) Then
719 Set _Database = ScriptForge.SF_Services.CreateScriptService(&quot;SFDatabases.Database&quot; _
720 , sDataSource, , , sUser, sPassword)
721 Else
722 Set _Database = ScriptForge.SF_Services.CreateScriptService(&quot;SFDatabases.Database&quot; _
723 , , _Form.DataSourceName, , sUser, sPassword)
724 End If
725 If IsNull(_Database) Then GoTo CatchConnect
726 End If
727 Else
728 EndIf
730 Finally:
731 Set GetDatabase = _Database
732 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
733 Exit Function
734 Catch:
735 GoTo Finally
736 CatchConnect:
737 ScriptForge.SF_Exception.RaiseFatal(DBCONNECTERROR, &quot;User&quot;, User, &quot;Password&quot;, Password, [_Super]._FileIdent())
738 GoTo Finally
739 End Function &apos; SFDocuments.SF_Form.GetDatabase
741 REM -----------------------------------------------------------------------------
742 Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
743 &apos;&apos;&apos; Return the actual value of the given property
744 &apos;&apos;&apos; Args:
745 &apos;&apos;&apos; PropertyName: the name of the property as a string
746 &apos;&apos;&apos; Returns:
747 &apos;&apos;&apos; The actual value of the property
748 &apos;&apos;&apos; Exceptions:
749 &apos;&apos;&apos; ARGUMENTERROR The property does not exist
750 &apos;&apos;&apos; Examples:
751 &apos;&apos;&apos; oDlg.GetProperty(&quot;Caption&quot;)
753 Const cstThisSub = &quot;SFDocuments.Form.GetProperty&quot;
754 Const cstSubArgs = &quot;&quot;
756 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
757 GetProperty = Null
759 Check:
760 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
761 If Not ScriptForge.SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
762 End If
764 Try:
765 GetProperty = _PropertyGet(PropertyName)
767 Finally:
768 SF_Utils._ExitFunction(cstThisSub)
769 Exit Function
770 Catch:
771 GoTo Finally
772 End Function &apos; SFDocuments.SF_Form.GetProperty
774 REM -----------------------------------------------------------------------------
775 Public Function Methods() As Variant
776 &apos;&apos;&apos; Return the list of public methods of the Form service as an array
778 Methods = Array( _
779 &quot;Activate&quot; _
780 , &quot;CloseForm&quot; _
781 , &quot;Controls&quot; _
782 , &quot;GetDatabase&quot; _
783 , &quot;MoveFirst&quot; _
784 , &quot;MoveLast&quot; _
785 , &quot;MoveNew&quot; _
786 , &quot;MoveNext&quot; _
787 , &quot;MovePrevious&quot; _
788 , &quot;Requery&quot; _
789 , &quot;SubForms&quot; _
792 End Function &apos; SFDocuments.SF_Form.Methods
794 REM -----------------------------------------------------------------------------
795 Public Function MoveFirst() As Boolean
796 &apos;&apos;&apos; The cursor is (re)positioned on the first row
797 &apos;&apos;&apos; Args:
798 &apos;&apos;&apos; Returns:
799 &apos;&apos;&apos; True if cursor move is successful
800 &apos;&apos;&apos; Example:
801 &apos;&apos;&apos; myForm.MoveFirst()
803 Dim bMoveFirst As Boolean &apos; Return value
804 Const cstThisSub = &quot;SFDocuments.Form.MoveFirst&quot;
805 Const cstSubArgs = &quot;&quot;
807 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
808 bMoveFirst = False
810 Check:
811 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
812 If Not _IsStillAlive() Then GoTo Finally
813 End If
814 Try:
815 With _Form
816 bMoveFirst = .first()
817 End With
819 Finally:
820 MoveFirst = bMoveFirst
821 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
822 Exit Function
823 Catch:
824 GoTo Finally
825 End Function &apos; SFDocuments.SF_Form.MoveFirst
827 REM -----------------------------------------------------------------------------
828 Public Function MoveLast() As Boolean
829 &apos;&apos;&apos; The cursor is (re)positioned on the last row
830 &apos;&apos;&apos; Args:
831 &apos;&apos;&apos; Returns:
832 &apos;&apos;&apos; True if cursor move is successful
833 &apos;&apos;&apos; Example:
834 &apos;&apos;&apos; myForm.MoveLast()
836 Dim bMoveLast As Boolean &apos; Return value
837 Const cstThisSub = &quot;SFDocuments.Form.MoveLast&quot;
838 Const cstSubArgs = &quot;&quot;
840 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
841 bMoveLast = False
843 Check:
844 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
845 If Not _IsStillAlive() Then GoTo Finally
846 End If
847 Try:
848 With _Form
849 bMoveLast = .last()
850 End With
852 Finally:
853 MoveLast = bMoveLast
854 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
855 Exit Function
856 Catch:
857 GoTo Finally
858 End Function &apos; SFDocuments.SF_Form.MoveLast
860 REM -----------------------------------------------------------------------------
861 Public Function MoveNew() As Boolean
862 &apos;&apos;&apos; The cursor is (re)positioned in the new record area
863 &apos;&apos;&apos; Args:
864 &apos;&apos;&apos; Returns:
865 &apos;&apos;&apos; True if cursor move is successful
866 &apos;&apos;&apos; Example:
867 &apos;&apos;&apos; myForm.MoveNew()
869 Dim bMoveNew As Boolean &apos; Return value
870 Const cstThisSub = &quot;SFDocuments.Form.MoveNew&quot;
871 Const cstSubArgs = &quot;&quot;
873 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
874 bMoveNew = False
876 Check:
877 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
878 If Not _IsStillAlive() Then GoTo Finally
879 End If
880 Try:
881 With _Form
882 .last() &apos; To simulate the behaviour in the UI
883 .moveToInsertRow()
884 End With
885 bMoveNew = True
887 Finally:
888 MoveNew = bMoveNew
889 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
890 Exit Function
891 Catch:
892 GoTo Finally
893 End Function &apos; SFDocuments.SF_Form.MoveNew
895 REM -----------------------------------------------------------------------------
896 Public Function MoveNext(Optional ByVal Offset As Variant) As Boolean
897 &apos;&apos;&apos; The cursor is (re)positioned on the next row
898 &apos;&apos;&apos; Args:
899 &apos;&apos;&apos; Offset: The number of records to go forward (default = 1)
900 &apos;&apos;&apos; Returns:
901 &apos;&apos;&apos; True if cursor move is successful
902 &apos;&apos;&apos; Example:
903 &apos;&apos;&apos; myForm.MoveNext()
905 Dim bMoveNext As Boolean &apos; Return value
906 Dim lOffset As Long &apos; Alias of Offset
907 Const cstThisSub = &quot;SFDocuments.Form.MoveNext&quot;
908 Const cstSubArgs = &quot;&quot;
910 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
911 bMoveNext = False
913 Check:
914 If IsMissing(Offset) Or IsEmpty(Offset) Then Offset = 1
915 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
916 If Not _IsStillAlive() Then GoTo Finally
917 If Not ScriptForge.SF_Utils._Validate(Offset, &quot;Offset&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
918 End If
919 Try:
920 lOffset = CLng(Offset) &apos; To be sure to have the right argument type
921 With _Form
922 If lOffset = 1 Then bMoveNext = .next() Else bMoveNext = .relative(lOffset)
923 End With
925 Finally:
926 MoveNext = bMoveNext
927 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
928 Exit Function
929 Catch:
930 GoTo Finally
931 End Function &apos; SFDocuments.SF_Form.MoveNext
933 REM -----------------------------------------------------------------------------
934 Public Function MovePrevious(Optional ByVal Offset As Variant) As Boolean
935 &apos;&apos;&apos; The cursor is (re)positioned on the previous row
936 &apos;&apos;&apos; Args:
937 &apos;&apos;&apos; Offset: The number of records to go backward (default = 1)
938 &apos;&apos;&apos; Returns:
939 &apos;&apos;&apos; True if cursor move is successful
940 &apos;&apos;&apos; Example:
941 &apos;&apos;&apos; myForm.MovePrevious()
943 Dim bMovePrevious As Boolean &apos; Return value
944 Dim lOffset As Long &apos; Alias of Offset
945 Const cstThisSub = &quot;SFDocuments.Form.MovePrevious&quot;
946 Const cstSubArgs = &quot;&quot;
948 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
949 bMovePrevious = False
951 Check:
952 If IsMissing(Offset) Or IsEmpty(Offset) Then Offset = 1
953 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
954 If Not _IsStillAlive() Then GoTo Finally
955 If Not ScriptForge.SF_Utils._Validate(Offset, &quot;Offset&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
956 End If
957 Try:
958 lOffset = CLng(Offset) &apos; To be sure to have the right argument type
959 With _Form
960 If lOffset = 1 Then bMovePrevious = .previous() Else bMovePrevious = .relative(-lOffset)
961 End With
963 Finally:
964 MovePrevious = bMovePrevious
965 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
966 Exit Function
967 Catch:
968 GoTo Finally
969 End Function &apos; SFDocuments.SF_Form.MovePrevious
971 REM -----------------------------------------------------------------------------
972 Public Function Properties() As Variant
973 &apos;&apos;&apos; Return the list or properties of the Form class as an array
975 Properties = Array( _
976 &quot;AllowDeletes&quot; _
977 , &quot;AllowInserts&quot; _
978 , &quot;AllowUpdates&quot; _
979 , &quot;BaseForm&quot; _
980 , &quot;Bookmark&quot; _
981 , &quot;CurrentRecord&quot; _
982 , &quot;Filter&quot; _
983 , &quot;LinkChildFields&quot; _
984 , &quot;LinkParentFields&quot; _
985 , &quot;Name&quot; _
986 , &quot;OnApproveCursorMove&quot; _
987 , &quot;OnApproveParameter&quot; _
988 , &quot;OnApproveReset&quot; _
989 , &quot;OnApproveRowChange&quot; _
990 , &quot;OnApproveSubmit&quot; _
991 , &quot;OnConfirmDelete&quot; _
992 , &quot;OnCursorMoved&quot; _
993 , &quot;OnErrorOccurred&quot; _
994 , &quot;OnLoaded&quot; _
995 , &quot;OnReloaded&quot; _
996 , &quot;OnReloading&quot; _
997 , &quot;OnResetted&quot; _
998 , &quot;OnRowChanged&quot; _
999 , &quot;OnUnloaded&quot; _
1000 , &quot;OnUnloading&quot; _
1001 , &quot;OrderBy&quot; _
1002 , &quot;Parent&quot; _
1003 , &quot;RecordSource&quot; _
1004 , &quot;XForm&quot; _
1007 End Function &apos; SFDocuments.SF_Form.Properties
1009 REM -----------------------------------------------------------------------------
1010 Public Function Requery() As Boolean
1011 &apos;&apos;&apos; Reload from the database the actual data into the form
1012 &apos;&apos;&apos; The cursor is (re)positioned on the first row
1013 &apos;&apos;&apos; Args:
1014 &apos;&apos;&apos; Returns:
1015 &apos;&apos;&apos; True if requery is successful
1016 &apos;&apos;&apos; Example:
1017 &apos;&apos;&apos; myForm.Requery()
1019 Dim bRequery As Boolean &apos; Return value
1020 Const cstThisSub = &quot;SFDocuments.Form.Requery&quot;
1021 Const cstSubArgs = &quot;&quot;
1023 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1024 bRequery = False
1026 Check:
1027 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1028 If Not _IsStillAlive() Then GoTo Finally
1029 End If
1030 Try:
1031 With _Form
1032 If .isLoaded() Then .reload() Else .load()
1033 End With
1034 bRequery = True
1036 Finally:
1037 Requery = bRequery
1038 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1039 Exit Function
1040 Catch:
1041 GoTo Finally
1042 End Function &apos; SFDocuments.SF_Form.Requery
1044 REM -----------------------------------------------------------------------------
1045 Public Function SetProperty(Optional ByVal PropertyName As Variant _
1046 , Optional ByRef Value As Variant _
1047 ) As Boolean
1048 &apos;&apos;&apos; Set a new value to the given property
1049 &apos;&apos;&apos; Args:
1050 &apos;&apos;&apos; PropertyName: the name of the property as a string
1051 &apos;&apos;&apos; Value: its new value
1052 &apos;&apos;&apos; Exceptions
1053 &apos;&apos;&apos; ARGUMENTERROR The property does not exist
1055 Const cstThisSub = &quot;SFDocuments.Form.SetProperty&quot;
1056 Const cstSubArgs = &quot;PropertyName, Value&quot;
1058 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1059 SetProperty = False
1061 Check:
1062 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1063 If Not SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
1064 End If
1066 Try:
1067 SetProperty = _PropertySet(PropertyName, Value)
1069 Finally:
1070 SF_Utils._ExitFunction(cstThisSub)
1071 Exit Function
1072 Catch:
1073 GoTo Finally
1074 End Function &apos; SFDocuments.SF_Form.SetProperty
1076 REM -----------------------------------------------------------------------------
1077 Public Function Subforms(Optional ByVal Subform As Variant) As Variant
1078 &apos;&apos;&apos; Return either
1079 &apos;&apos;&apos; - the list of the subforms contained in the actual form or subform instance
1080 &apos;&apos;&apos; - a SFDocuments.Form object based on its name or its index in the alphabetic list of subforms
1081 &apos;&apos;&apos; Args:
1082 &apos;&apos;&apos; Subform: a subform stored in the parent form given by its name or its index
1083 &apos;&apos;&apos; When absent, the list of available subforms is returned
1084 &apos;&apos;&apos; To get the first (unique ?) subform stored in the parent form, set Subform = 0
1085 &apos;&apos;&apos; Exceptions:
1086 &apos;&apos;&apos; SUBFORMNOTFOUNDERROR Subform not found
1087 &apos;&apos;&apos; Returns:
1088 &apos;&apos;&apos; A zero-based array of strings if Subform is absent
1089 &apos;&apos;&apos; An instance of the SF_Form class if Subform exists
1090 &apos;&apos;&apos; Example:
1091 &apos;&apos;&apos; Dim myForm As Object, myList As Variant, mySubform As Object
1092 &apos;&apos;&apos; myList = myForm.Subforms()
1093 &apos;&apos;&apos; Set mySubform = myForm.Subforms(&quot;mySubform&quot;)
1095 Dim oSubform As Object &apos; The new Form class instance
1096 Dim oXSubform As Object &apos; com.sun.star.form.XForm
1097 Dim vSubformNames As Variant &apos; Array of subform names
1098 Dim i As Long
1099 Const cstDrawPage = 0 &apos; Only 1 drawpage in a Writer document
1101 Const cstThisSub = &quot;SFDocuments.Form.Subforms&quot;
1102 Const cstSubArgs = &quot;[Subform=&quot;&quot;&quot;&quot;]&quot;
1104 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1106 Check:
1107 If IsMissing(Subform) Or IsEmpty(Subform) Then Subform = &quot;&quot;
1108 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1109 If Not _IsStillAlive() Then GoTo Finally
1110 If Not ScriptForge.SF_Utils._Validate(Subform, &quot;Subform&quot;, Array(V_STRING, ScriptForge.V_NUMERIC)) Then GoTo Finally
1111 End If
1113 Try:
1114 &apos; Collect all control names and retain only the subforms
1115 vSubformNames = _Form.getElementNames()
1116 For i = 0 To UBound(vSubformNames)
1117 Set oSubform = _Form.getByName(vSubformNames(i))
1118 &apos; Subforms are the only control types having no ClassId property
1119 If ScriptForge.SF_Session.HasUnoProperty(oSubform, &quot;ClassId&quot;) Then vSubformNames(i) = &quot;&quot;
1120 Next i
1121 vSubformNames = ScriptForge.SF_Array.TrimArray(vSubformNames)
1123 If Len(Subform) = 0 Then &apos; Return the list of valid subform names
1124 Subforms = vSubformNames
1125 Else
1126 If VarType(Subform) = V_STRING Then &apos; Find the form by name
1127 If Not ScriptForge.SF_Array.Contains(vSubformNames, Subform, CaseSensitive := True) Then GoTo CatchNotFound
1128 Set oXSubform = _Form.getByName(Subform)
1129 Else &apos; Find the form by index
1130 If Subform &lt; 0 Or Subform &gt; UBound(vSubformNames) Then GoTo CatchNotFound
1131 Set oXSubform = _Form.getByName(vSubformNames(Subform))
1132 End If
1133 &apos; Create the new Form class instance
1134 Set oSubform = SF_Register._NewForm(oXSubform)
1135 With oSubform
1136 Set .[_Parent] = [Me]
1137 ._FormType = ISSUBFORM
1138 Set ._Component = _Component
1139 Set ._BaseComponent = _BaseComponent
1140 Set ._FormDocument = _FormDocument
1141 ._SheetName = _SheetName
1142 ._FormDocumentName = _FormDocumentName
1143 Set ._Database = _Database
1144 ._Initialize()
1145 End With
1146 Set Subforms = oSubform
1147 End If
1149 Finally:
1150 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1151 Exit Function
1152 Catch:
1153 GoTo Finally
1154 CatchNotFound:
1155 ScriptForge.SF_Exception.RaiseFatal(SUBFORMNOTFOUNDERROR, Subform, _Name)
1156 GoTo Finally
1157 End Function &apos; SFDocuments.SF_Form.Subforms
1159 REM =========================================================== PRIVATE FUNCTIONS
1161 REM -----------------------------------------------------------------------------
1162 Public Function _GetEventName(ByVal psProperty As String) As String
1163 &apos;&apos;&apos; Return the LO internal event name derived from the SF property name
1164 &apos;&apos;&apos; The SF property name is not case sensitive, while the LO name is case-sensitive
1165 &apos; Corrects the typo on ErrorOccur(r?)ed, if necessary
1167 Dim vProperties As Variant &apos; Array of class properties
1168 Dim sProperty As String &apos; Correctly cased property name
1170 vProperties = Properties()
1171 sProperty = vProperties(ScriptForge.SF_Array.IndexOf(vProperties, psProperty, SortOrder := &quot;ASC&quot;))
1173 _GetEventName = LCase(Mid(sProperty, 3, 1)) &amp; Right(sProperty, Len(sProperty) - 3)
1175 End Function &apos; SFDocuments.SF_Form._GetEventName
1177 REM -----------------------------------------------------------------------------
1178 Private Function _GetListener(ByVal psEventName As String) As String
1179 &apos;&apos;&apos; Getting/Setting macros triggered by events requires a Listener-EventName pair
1180 &apos;&apos;&apos; Return the X...Listener corresponding with the event name in argument
1182 Select Case UCase(psEventName)
1183 Case UCase(&quot;OnApproveCursorMove&quot;)
1184 _GetListener = &quot;XRowSetApproveListener&quot;
1185 Case UCase(&quot;OnApproveParameter&quot;)
1186 _GetListener = &quot;XDatabaseParameterListener&quot;
1187 Case UCase(&quot;OnApproveReset&quot;), UCase(&quot;OnResetted&quot;)
1188 _GetListener = &quot;XResetListener&quot;
1189 Case UCase(&quot;OnApproveRowChange&quot;)
1190 _GetListener = &quot;XRowSetApproveListener&quot;
1191 Case UCase(&quot;OnApproveSubmit&quot;)
1192 _GetListener = &quot;XSubmitListener&quot;
1193 Case UCase(&quot;OnConfirmDelete&quot;)
1194 _GetListener = &quot;XConfirmDeleteListener&quot;
1195 Case UCase(&quot;OnCursorMoved&quot;), UCase(&quot;OnRowChanged&quot;)
1196 _GetListener = &quot;XRowSetListener&quot;
1197 Case UCase(&quot;OnErrorOccurred&quot;)
1198 _GetListener = &quot;XSQLErrorListener&quot;
1199 Case UCase(&quot;OnLoaded&quot;), UCase(&quot;OnReloaded&quot;), UCase(&quot;OnReloading&quot;), UCase(&quot;OnUnloaded&quot;), UCase(&quot;OnUnloading&quot;)
1200 _GetListener = &quot;XLoadListener&quot;
1201 End Select
1203 End Function &apos; SFDocuments.SF_Form._GetListener
1205 REM -----------------------------------------------------------------------------
1206 Private Sub _GetParents()
1207 &apos;&apos;&apos; When the current instance is created top-down, the parents are completely defined
1208 &apos;&apos;&apos; and nothing should be done in this method
1209 &apos;&apos;&apos; When the a class instance is created in a (form/control) event, it is the opposite
1210 &apos;&apos;&apos; The current method rebuilds the missing members in the instance from the bottom
1211 &apos;&apos;&apos; Members potentially to collect are:
1212 &apos;&apos;&apos; - _FormType
1213 &apos;&apos;&apos; - [_Parent], the immediate parent: a form or a document instance
1214 &apos;&apos;&apos; + Only when the _FormType is a main form
1215 &apos;&apos;&apos; - _SheetName (Calc only)
1216 &apos;&apos;&apos; - _FormDocumentName (Base only)
1217 &apos;&apos;&apos; - _FormDocument, the topmost form collection
1218 &apos;&apos;&apos; - _Component, the containing document
1219 &apos;&apos;&apos; They must be identified only starting from the _Form UNO object
1220 &apos;&apos;&apos;
1221 &apos;&apos;&apos; The method is called from the _Initialize() method at instance creation
1223 Dim oParent As Object &apos; Successive bottom-up parents
1224 Dim sType As String &apos; UNO object type
1225 Dim iLevel As Integer &apos; When = 1 =&gt; first parent
1226 Dim oBase As Object &apos; Empty Base instance
1227 Dim oSession As Object : Set oSession = ScriptForge.SF_Session
1229 On Local Error GoTo Finally &apos; Being probably called from events, this method should avoid failures
1230 &apos; When the form type is known, the upper part of the branch is not scanned
1231 If _FormType &lt;&gt; ISUNDEFINED Then GoTo Finally
1233 Try:
1234 &apos; The whole branch is scanned bottom-up
1235 If oSession.HasUnoProperty(_Form, &quot;Parent&quot;) Then Set oParent = _Form.Parent Else Set oParent = Nothing
1236 _FormType = ISUNDEFINED
1237 iLevel = 1
1239 Do While Not IsNull(oParent)
1240 sType = SF_Session.UnoObjectType(oParent)
1241 Select Case sType
1242 &apos; Collect at each level the needed info
1243 Case &quot;com.sun.star.comp.forms.ODatabaseForm&quot; &apos; The parent _Form of a subform
1244 If iLevel = 1 Then
1245 _FormType = ISSUBFORM
1246 Set [_Parent] = SF_Register._NewForm(oParent)
1247 &apos; Everything is in the parent, copy items and stop scan
1248 [_Parent]._Initialize() &apos; Current method is called recursively here
1249 With [_Parent]
1250 _SheetName = ._SheetName
1251 _FormDocumentName = ._FormDocumentName
1252 Set _FormDocument = ._FormDocument
1253 Set _Component = ._Component
1254 End With
1255 Exit Sub
1256 End If
1257 Case &quot;com.sun.star.form.OFormsCollection&quot; &apos; The collection of forms inside a drawpage
1258 Case &quot;SwXTextDocument&quot; &apos; The parent document: a Writer document or a Base form document
1259 If oParent.Identifier = &quot;com.sun.star.sdb.FormDesign&quot; Then
1260 _FormType = ISBASEFORM
1261 &apos; Make a new SF_FormDocument instance
1262 Set [_Parent] = ScriptForge.SF_Services.CreateScriptService(&quot;SFDocuments.FormDocument&quot;, oParent)
1263 Set _FormDocument = [_Parent]._FormDocument
1264 ElseIf oParent.Identifier = &quot;com.sun.star.text.TextDocument&quot; Then
1265 _FormType = ISDOCFORM
1266 Set [_Parent] = ScriptForge.SF_Services.CreateScriptService(&quot;SFDocuments.Document&quot;, oParent)
1267 End If
1268 Set _Component = oParent
1269 Case &quot;ScModelObj&quot; &apos; The parent document: a Calc document
1270 _FormType = ISCALCFORM
1271 Set [_Parent] = ScriptForge.SF_Services.CreateScriptService(&quot;SFDocuments.Document&quot;, oParent)
1272 Set _Component = oParent
1273 &apos; The triggered form event is presumed to be located in the (drawpage of the) active sheet
1274 _SheetName = [_Parent].XSpreadsheet(&quot;~&quot;)
1275 Case &quot;com.sun.star.comp.dba.ODatabaseDocument&quot; &apos; The Base document
1276 Case Else
1277 End Select
1278 If oSession.HasUnoProperty(oParent, &quot;Parent&quot;) Then Set oParent = oParent.Parent Else Set oParent = Nothing
1279 iLevel = iLevel + 1
1280 Loop
1282 Finally:
1283 Exit Sub
1284 End Sub &apos; SFDocuments.SF_Form._GetParents
1286 REM -----------------------------------------------------------------------------
1287 Public Sub _Initialize()
1288 &apos;&apos;&apos; Achieve the creation of a SF_Form instance
1289 &apos;&apos;&apos; - complete the missing private members
1290 &apos;&apos;&apos; - store the new instance in the cache
1292 _GetParents()
1293 _CacheIndex = SF_Register._AddFormToCache(_Form, [Me])
1295 End Sub &apos; SFDocuments.SF_Form._Initialize
1297 REM -----------------------------------------------------------------------------
1298 Private Function _IsStillAlive(Optional ByVal pbError As Boolean) As Boolean
1299 &apos;&apos;&apos; Return True if the Form is still open
1300 &apos;&apos;&apos; If dead the actual instance is disposed
1301 &apos;&apos;&apos; and the execution is cancelled when pbError = True (default)
1302 &apos;&apos;&apos; Args:
1303 &apos;&apos;&apos; pbError: if True (default), raise a fatal error
1305 Dim bAlive As Boolean &apos; Return value
1306 Dim sName As String &apos; Alias of _Name
1307 Dim sId As String &apos; Alias of FileIdent
1309 Check:
1310 On Local Error GoTo Catch &apos; Anticipate DisposedException errors or alike
1311 If IsMissing(pbError) Then pbError = True
1313 Try:
1314 &apos; At main form termination, all database connections are lost
1315 bAlive = Not IsNull(_Form)
1316 If Not bAlive Then GoTo Catch
1318 Finally:
1319 _IsStillAlive = bAlive
1320 Exit Function
1321 Catch:
1322 bAlive = False
1323 On Error GoTo 0
1324 &apos; Keep error message elements before disposing the instance
1325 sName = _SheetName &amp; _FormDocumentName &apos; At least one of them is a zero-length string
1326 sName = Iif(Len(sName) &gt; 0, &quot;[&quot; &amp; sName &amp; &quot;].&quot;, &quot;&quot;) &amp; _Name
1327 If Not IsNull(_Component) Then sId = _Component.Location Else sId = &quot;&quot;
1328 &apos; Dispose the actual forms instance
1329 Dispose()
1330 &apos; Display error message
1331 If pbError Then ScriptForge.SF_Exception.RaiseFatal(FORMDEADERROR, sName, sId)
1332 GoTo Finally
1333 End Function &apos; SFDocuments.SF_Form._IsStillAlive
1335 REM -----------------------------------------------------------------------------
1336 Private Function _PropertyGet(Optional ByVal psProperty As String) As Variant
1337 &apos;&apos;&apos; Return the value of the named property
1338 &apos;&apos;&apos; Args:
1339 &apos;&apos;&apos; psProperty: the name of the property
1341 Static oSession As Object &apos; Alias of SF_Session
1342 Dim vBookmark As Variant &apos; Form bookmark
1343 Dim cstThisSub As String
1344 Const cstSubArgs = &quot;&quot;
1346 cstThisSub = &quot;SFDocuments.Form.get&quot; &amp; psProperty
1347 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1349 ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
1350 _PropertyGet = Empty
1351 If Not _IsStillAlive() Then GoTo Finally
1353 If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService(&quot;Session&quot;)
1354 Select Case UCase(psProperty)
1355 Case UCase(&quot;AllowDeletes&quot;)
1356 If Not IsNull(_Form) Then _PropertyGet = _Form.AllowDeletes
1357 Case UCase(&quot;AllowInserts&quot;)
1358 If Not IsNull(_Form) Then _PropertyGet = _Form.AllowInserts
1359 Case UCase(&quot;AllowUpdates&quot;)
1360 If Not IsNull(_Form) Then _PropertyGet = _Form.AllowUpdates
1361 Case UCase(&quot;BaseForm&quot;)
1362 _PropertyGet = _FormDocumentName
1363 Case UCase(&quot;Bookmark&quot;)
1364 If IsNull(_Form) Then
1365 _PropertyGet = 0
1366 Else
1367 On Local Error Resume Next &apos; Disable error handler because bookmarking does not always react well in events ...
1368 If _Form.IsBookmarkable Then vBookmark = _Form.getBookmark() Else vBookmark = Nothing
1369 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error Goto Catch Else On Local Error Goto 0
1370 If IsNull(vBookmark) Then Goto Catch
1371 _PropertyGet = vBookmark
1372 End If
1373 Case UCase(&quot;CurrentRecord&quot;)
1374 If IsNull(_Form) Then _PropertyGet = 0 Else _PropertyGet = _Form.Row
1375 Case UCase(&quot;Filter&quot;)
1376 If IsNull(_Form) Then _PropertyGet = &quot;&quot; Else _PropertyGet = _Form.Filter
1377 Case UCase(&quot;LinkChildFields&quot;)
1378 If IsNull(_Form) Or _FormType &lt;&gt; ISSUBFORM Then _PropertyGet = Array() Else _PropertyGet = _Form.DetailFields
1379 Case UCase(&quot;LinkParentFields&quot;)
1380 If IsNull(_Form) Or _FormType &lt;&gt; ISSUBFORM Then _PropertyGet = Array() Else _PropertyGet = _Form.MasterFields
1381 Case UCase(&quot;Name&quot;)
1382 _PropertyGet = _Name
1383 Case UCase(&quot;OnApproveCursorMove&quot;), UCase(&quot;OnApproveParameter&quot;), UCase(&quot;OnApproveReset&quot;), UCase(&quot;OnApproveRowChange&quot;) _
1384 , UCase(&quot;OnApproveSubmit&quot;), UCase(&quot;OnConfirmDelete&quot;), UCase(&quot;OnCursorMoved&quot;), UCase(&quot;OnErrorOccurred&quot;) _
1385 , UCase(&quot;OnLoaded&quot;), UCase(&quot;OnReloaded&quot;), UCase(&quot;OnReloading&quot;), UCase(&quot;OnResetted&quot;), UCase(&quot;OnRowChanged&quot;) _
1386 , UCase(&quot;OnUnloaded&quot;), UCase(&quot;OnUnloading&quot;)
1387 If IsNull(_Form) Then _PropertyGet = &quot;&quot; Else _PropertyGet = SF_Register._GetEventScriptCode(_Form, psProperty, _Name)
1388 Case UCase(&quot;OrderBy&quot;)
1389 If IsNull(_Form) Then _PropertyGet = &quot;&quot; Else _PropertyGet = _Form.Order
1390 Case UCase(&quot;Parent&quot;)
1391 _PropertyGet = [_Parent]
1392 Case UCase(&quot;RecordSource&quot;)
1393 If IsNull(_Form) Then _PropertyGet = &quot;&quot; Else _PropertyGet = _Form.Command
1394 Case UCase(&quot;XForm&quot;)
1395 Set _PropertyGet = _Form
1396 Case Else
1397 _PropertyGet = Null
1398 End Select
1400 Finally:
1401 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1402 Exit Function
1403 Catch:
1404 GoTo Finally
1405 End Function &apos; SFDocuments.SF_Form._PropertyGet
1407 REM -----------------------------------------------------------------------------
1408 Private Function _PropertySet(Optional ByVal psProperty As String _
1409 , Optional ByVal pvValue As Variant _
1410 ) As Boolean
1411 &apos;&apos;&apos; Set the new value of the named property
1412 &apos;&apos;&apos; Args:
1413 &apos;&apos;&apos; psProperty: the name of the property
1414 &apos;&apos;&apos; pvValue: the new value of the given property
1415 &apos;&apos;&apos; Returns:
1416 &apos;&apos;&apos; True if successful
1418 Dim bSet As Boolean &apos; Return value
1419 Dim oDatabase As Object &apos; Database class instance
1420 Dim lCommandType As Long &apos; Record source type: 0 = Table, 1 = Query, 2 = SELECT
1421 Dim sCommand As String &apos; Record source
1422 Static oSession As Object &apos; Alias of SF_Session
1423 Dim cstThisSub As String
1424 Const cstSubArgs = &quot;Value&quot;
1426 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1427 bSet = False
1429 cstThisSub = &quot;SFDocuments.Form.set&quot; &amp; psProperty
1430 ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
1431 If Not _IsStillAlive() Then GoTo Finally
1433 If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService(&quot;Session&quot;)
1434 bSet = True
1435 Select Case UCase(psProperty)
1436 Case UCase(&quot;AllowDeletes&quot;)
1437 If Not ScriptForge.SF_Utils._Validate(pvValue, &quot;AllowDeletes&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
1438 If Not IsNull(_Form) Then
1439 _Form.AllowDeletes = pvValue
1440 _Form.reload()
1441 End If
1442 Case UCase(&quot;AllowInserts&quot;)
1443 If Not ScriptForge.SF_Utils._Validate(pvValue, &quot;AllowInserts&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
1444 If Not IsNull(_Form) Then
1445 _Form.AllowInserts = pvValue
1446 _Form.reload()
1447 End If
1448 Case UCase(&quot;AllowUpdates&quot;)
1449 If Not ScriptForge.SF_Utils._Validate(pvValue, &quot;AllowUpdates&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
1450 If Not IsNull(_Form) Then
1451 _Form.AllowUpdates = pvValue
1452 _Form.reload()
1453 End If
1454 Case UCase(&quot;Bookmark&quot;)
1455 If Not ScriptForge.SF_Utils._Validate(pvValue, &quot;Bookmark&quot;, Array(ScriptForge.V_NUMERIC, ScriptForge.V_OBJECT)) Then GoTo Finally
1456 If Not IsNull(pvValue) And Not IsNull(_Form) Then bSet = _Form.moveToBookmark(pvValue)
1457 Case UCase(&quot;CurrentRecord&quot;)
1458 If Not ScriptForge.SF_Utils._Validate(pvValue, &quot;CurrentRecord&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
1459 If Not IsNull(_Form) Then bSet = _Form.absolute(pvValue)
1460 Case UCase(&quot;Filter&quot;)
1461 If Not ScriptForge.SF_Utils._Validate(pvValue, &quot;Filter&quot;, V_STRING) Then GoTo Finally
1462 If Not IsNull(_Form) Then
1463 With _Form
1464 If Len(pvValue) &gt; 0 Then
1465 Set oDatabase = GetDatabase()
1466 If Not IsNull(oDatabase) Then .Filter = oDatabase._ReplaceSquareBrackets(pvValue) Else .Filter = pvValue
1467 Else
1468 .Filter = &quot;&quot;
1469 End If
1470 .ApplyFilter = True
1471 .reload()
1472 End With
1473 End If
1474 Case UCase(&quot;OnApproveCursorMove&quot;), UCase(&quot;OnApproveParameter&quot;), UCase(&quot;OnApproveReset&quot;), UCase(&quot;OnApproveRowChange&quot;) _
1475 , UCase(&quot;OnApproveSubmit&quot;), UCase(&quot;OnConfirmDelete&quot;), UCase(&quot;OnCursorMoved&quot;), UCase(&quot;OnErrorOccurred&quot;) _
1476 , UCase(&quot;OnLoaded&quot;), UCase(&quot;OnReloaded&quot;), UCase(&quot;OnReloading&quot;), UCase(&quot;OnResetted&quot;), UCase(&quot;OnRowChanged&quot;) _
1477 , UCase(&quot;OnUnloaded&quot;), UCase(&quot;OnUnloading&quot;)
1478 If Not ScriptForge.SF_Utils._Validate(pvValue, psProperty, V_STRING) Then Goto Finally
1479 If Not IsNull(_Form) Then
1480 bSet = SF_Register._RegisterEventScript(_Form _
1481 , psProperty _
1482 , _GetListener(psProperty) _
1483 , pvValue _
1484 , _Name _
1486 End If
1487 Case UCase(&quot;OrderBy&quot;)
1488 If Not ScriptForge.SF_Utils._Validate(pvValue, &quot;OrderBy&quot;, V_STRING) Then GoTo Finally
1489 If Not IsNull(_Form) Then
1490 With _Form
1491 If Len(pvValue) &gt; 0 Then
1492 Set oDatabase = GetDatabase()
1493 If Not IsNull(oDatabase) Then .Order = oDatabase._ReplaceSquareBrackets(pvValue) Else .Order = pvValue
1494 Else
1495 .Order = &quot;&quot;
1496 End If
1497 .reload()
1498 End With
1499 End If
1500 Case UCase(&quot;RecordSource&quot;)
1501 If Not ScriptForge.SF_Utils._Validate(pvValue, &quot;RecordSource&quot;, V_STRING) Then GoTo Finally
1502 If Not IsNull(_Form) And Len(pvValue) &gt; 0 Then
1503 Set oDatabase = GetDatabase()
1504 If Not IsNull(oDatabase) Then
1505 With oDatabase
1506 If ScriptForge.SF_Array.Contains(.Tables, pvValue, CaseSensitive := True) Then
1507 sCommand = pvValue
1508 lCommandType = com.sun.star.sdb.CommandType.TABLE
1509 ElseIf ScriptForge.SF_Array.Contains(.Queries, pvValue, CaseSensitive := True) Then
1510 sCommand = pvValue
1511 lCommandType = com.sun.star.sdb.CommandType.QUERY
1512 ElseIf ScriptForge.SF_String.StartsWith(pvValue, &quot;SELECT&quot;, CaseSensitive := False) Then
1513 sCommand = .ReplaceSquareBrackets(pvValue)
1514 lCommandType = com.sun.star.sdb.CommandType.COMMAND
1515 End If
1516 _Form.Command = sCommand
1517 _Form.CommandType = lCommandType
1518 End With
1519 End If
1520 End If
1521 Case Else
1522 bSet = False
1523 End Select
1525 Finally:
1526 _PropertySet = bSet
1527 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1528 Exit Function
1529 Catch:
1530 GoTo Finally
1531 End Function &apos; SFDocuments.SF_Form._PropertySet
1533 REM -----------------------------------------------------------------------------
1534 Private Function _Repr() As String
1535 &apos;&apos;&apos; Convert the Model instance to a readable string, typically for debugging purposes (DebugPrint ...)
1536 &apos;&apos;&apos; Args:
1537 &apos;&apos;&apos; Return:
1538 &apos;&apos;&apos; &quot;[Form]: Name&quot;
1540 Dim sParent As String &apos; To recognize the parent
1542 sParent = _SheetName &amp; _FormDocumentName &apos; At least one of them is a zero-length string
1543 _Repr = &quot;[Form]: &quot; &amp; Iif(Len(sParent) &gt; 0, sParent &amp; &quot;...&quot;, &quot;&quot;) &amp; _Name
1545 End Function &apos; SFDocuments.SF_Form._Repr
1547 REM ============================================ END OF SFDOCUMENTS.SF_FORM
1548 </script:module>