SFDocuments.Form service

The Form service provides methods and properties to manage forms in LibreOffice documents. This service supports forms in Base, Calc and Writer documents and allows to:

tip

The SFDocuments.Form service is available from LibreOffice 7.2 onwards.


Forms are usually used in LibreOffice documents to create user interfaces connected to relational databases. Hence, the Form service provides quick access to the linked database through the SFDatabases.Database service.

tip

The SFDocuments.Form service is closely related to the SFDocuments.FormControl service.


Meghatározások

FormDocument

Forms are usually created in Base documents, but they can be added to Writer and Calc documents as well.

A Base-ban minden űrlap, amelyet a Beszúrás - Űrlap funkcióval vagy az Űrlaptündér segítségével hoz létre, valójában egy FormDocument, amelyet a Form szolgáltatással lehet kezelni. A Base dokumentumok korlátlan számú űrlapdokumentumot tartalmazhatnak.

Az alábbiakban egy példa mutatja az összes elem hierarchiáját, amely egy Base dokumentumban az űrlapok és alűrlapok eléréséhez szükséges. Tegyük fel, hogy van egy Employees.odb nevű Base fájlunk, és ezen belül létrehoztunk egy űrlapdokumentumot az új alkalmazottak adatbázisba való felvételéhez. Az űrlapdokumentum tartalmaz egy EmployeeData nevű fő űrlapot, amely hozzáférést biztosít egy táblázathoz. Van egy WorksAtPlant alűrlap is, amely lehetővé teszi az új alkalmazott hozzárendelését a vállalat egyik üzeméhez.


    Employees.odb (Base dokumentum)
     |
     |-- AddEmployee (FormDocument)
          |
          |-- EmployeeData (Main Form)
               |
               |-- WorksAtPlant (SubForm)
  
note

A FormDocument olyan űrlapok halmazának tekinthető, amelyek a LibreOffice dokumentumokon belül hozzáférést biztosítanak az adatállományokhoz, például az adatbázis tábláihoz és lekérdezéseihez. A FormDocument-en belüli űrlapok és alűrlapok nevei a Form Navigator segítségével érhetők el.


Űrlapok és alűrlapok

Egy űrlapdokumentum egy vagy több űrlapból áll, amelyek viszont tetszőleges számú alűrlapot is tartalmazhatnak. Az űrlap olyan vezérlőelemek absztrakt halmaza, amelyek egy meghatározott adatforráshoz kapcsolódnak, amely lehet egy adatbázis-tábla, egy lekérdezés vagy egy SQL SELECT utasítás.

A Calc és Writer dokumentumokban az egyes űrlapok különböző adatbázisokban található adatkészletekhez kapcsolhatók. Ezzel ellentétben a Base dokumentumokban a dokumentumban található adatbázis minden űrlap számára közös.

tip

To invoke the SFDocuments.Form service refer to the methods Forms(), FormDocuments() and OpenFormDocument() of the SFDocuments.Document service


A szolgáltatás igénybevétele

Before using the Form service the ScriptForge library needs to be loaded or imported:

note

• Basic macros require to load ScriptForge library using the following statement:
GlobalScope.BasicLibraries.loadLibrary("ScriptForge")

• Python scripts require an import from scriptforge module:
from scriptforge import CreateScriptService


Writer dokumentumokban

The code snippet below shows how to access the form named Form1 that is inside a Writer file:


      Dim oDoc As Object, myForm As Object, ui as Object
      Set ui = CreateScriptService("UI")
      Set oDoc = ui.OpenDocument("/home/user/Documents/MyForm.odt")
      Set myForm = oDoc.Forms("Form1")
   
A Python nyelvben

     from scriptforge import CreateScriptService
     ui = CreateScriptService('UI') 
     doc = ui.OpenDocument('/home/user/Documents/MyForm.odt')
     my_form = doc.Forms('Form1')
   

Forms can be accessed by their names or by their indices, as shown below:


     Set myForm = oDoc.Forms(0)
   
A Python nyelvben

     my_form = doc.Forms(0)
   
warning

If you try to access a FormDocument that is currently opened in Design Mode an exception will be raised.


Calc dokumentumokban

Egy Calc fájlban lévő űrlapnak egyedi névvel kell rendelkeznie a munkalapon belül. Ezért a Forms metódus két argumentumot igényel, az első a munkalap nevét, a második pedig az űrlap nevét adja meg.


      Dim oDoc As Object, myForm As Object, ui as Object
      Set ui = CreateScriptService("UI")
      Set oDoc = ui.OpenDocument("/home/user/Documents/MyForms.ods")
      Set myForm = oDoc.Forms("Sheet1", "Form1")
   

This is achieved identically using Python:


     ui = CreateScriptService('UI')
     doc = ui.OpenDocument('/home/user/Documents/MyForms.ods')
     my_form = doc.Forms('Sheet1', 'Form1')
   

Base dokumentumokban

A FormDocument inside a Base document is accessed by its name. The following example opens the form document named thisFormDocument and accesses the form MainForm:


      Dim oDb As Object, myForm As Object
      Set oDb = CreateScriptService("SFDocuments.Document", ThisDatabaseDocument)
      ' The statement below is necessary only if the form hasn't been opened yet
      oDb.OpenFormDocument("thisFormDocument")
      Set myForm = oDoc.Forms("thisFormDocument", "MainForm")
      ' Or, alternatively, to access the form by its index ...
      Set myForm = oDb.Forms("thisFormDocument", 0)
   
note

Ahhoz, hogy a Form szolgáltatást használó űrlapon bármilyen műveletet végre lehessen hajtani, a FormDocument dokumentumot a felhasználónak vagy kézzel, vagy programozottan, egy felhasználói parancsfájlban kell megnyitnia. Ez utóbbit a Base szolgáltatás OpenFormDocument metódusának meghívásával lehet megtenni.


To access a given subform of a form use the SubForms method. Note that in the example below mySubForm is a new instance of the Form service.


     Dim mySubForm As Object
     Set mySubForm = myForm.SubForms("mySubForm")
   

Previous examples translate in Python as:


     db = CreateScriptService('SFDocuments.Document', XSCRIPTCONTEXT.getDocument())
     #  The statement below is necessary only if the form hasn't been opened yet
     form_doc = db.OpenFormDocument('thisFormDocument')
     form = form_doc.Forms('thisFormDocument', 'MainForm')
     #  Or, alternatively, to access the form by its index ...
     form = form_doc.Forms('thisFormDocument', 0)
     sub_form = form.SubForms('mySubForm')
   

Form eseményekben

To invoke the Form service when a form event takes place:


      Sub OnEvent(ByRef poEvent As Object)
          Dim myForm As Object
          Set myForm = CreateScriptService("SFDocuments.FormEvent", poEvent)
          '(...)
      End sub
   
A Python nyelvben

     def OnEvent(event: uno):
         form = CreateScriptService('SFDocuments.FormEvent', event)
         pass
   
note

The FormEvent service is used exclusively to create instances of the SFDocuments.Form and SFDocuments.FormControl services when a form or control event takes place.


It is recommended to free resources after use of the Form service.


     myForm.Dispose() ' Basic
   

     form.Dispose()  # Python
   

This operation is done implicitly when a form document is closed with the CloseFormDocument() method described below.

Tulajdonságok

Név

Írásvédett

Típus

Leírás

AllowDeletes

Nem

Boolean

Specifies if the form allows to delete records.

AllowInserts

Nem

Boolean

Specifies if the form allows to add records.

AllowUpdates

Nem

Boolean

Specifies if the form allows to update records.

BaseForm

Igen

String

Specifies the hierarchical name of the Base Form containing the actual form.

Bookmark

Nem

Variant

Specifies uniquely the current record of the form's underlying table, query or SQL statement.

CurrentRecord

Nem

Long

Azonosítja az űrlapon megtekintett adatkészlet aktuális rekordját. Ha a sor száma pozitív, a kurzor az eredményhalmaz elejéhez képest a megadott sor számára mozog. A sorok száma 1-nél kezdődik. Ha a megadott sor száma negatív, a kurzor az eredményhalmaz végéhez viszonyított abszolút sorpozícióra mozog. A sor -1 az eredményhalmaz utolsó sorára utal.

Filter

Nem

String

Specifies a subset of records to be displayed as a SQL WHERE-clause without the WHERE keyword.

LinkChildFields

Igen

String

Specifies how records in a child subform are linked to records in its parent form.

LinkParentFields

Igen

String

Specifies how records in a child subform are linked to records in its parent form.

Name

Igen

String

The name of the current form.

OrderBy

Nem

String

Specifies in which order the records should be displayed as a SQL ORDER BY clause without the ORDER BY keywords.

Parent

Igen

Object

The parent of the current form. It can be either a SFDocuments.Form or a SFDocuments.Document object.

RecordSource

Nem

String

Specifies the source of the data, as a table name, a query name or a SQL statement.

XForm

Igen

UNO
objektum

The UNO object representing interactions with the form. Refer to XForm and DataForm in the API documentation for detailed information.


Esemény tulajdonságai

The properties below return or set URI strings that define the script triggered by the event.

Név

Írásvédett

Basic IDE leírás

OnApproveCursorMove

Nem

Rekordváltozás előtt

OnApproveParameter

Nem

Paraméterek kitöltése

OnApproveReset

Nem

Alaphelyzetbe állítás előtt

OnApproveRowChange

Nem

Rekordművelet előtt

OnApproveSubmit

Nem

Elküldés előtt

OnConfirmDelete

Nem

Törlés megerősítése

OnCursorMoved

Nem

Rekordváltozás után

OnErrorOccurred

Nem

Hiba történt

OnLoaded

Nem

Töltés közben

OnReloaded

Nem

Újratöltéskor

OnReloading

Nem

Újratöltés előtt

OnResetted

Nem

Alaphelyzetbe állítás után

OnRowChanged

Nem

Rekordművelet után

OnUnloaded

Nem

Kilépéskor

OnUnloading

Nem

Kilépés előtt


tip

To learn more about URI strings, refer to the Scripting Framework URI Specification.


List of methods in the Form service

Activate
CloseFormDocument
Controls
GetDatabase

MoveFirst
MoveLast
MoveNext
MoveNew

MovePrevious
Requery
SubForms


Activate

Sets the focus on the current Form instance. Returns True if focusing was successful.

The behavior of the Activate method depends on the type of document where the form is located:

Szintaxis:

svc.Activate(): bool

Példa:

A következő példa feltételezi, hogy a jelenleg megnyitott Calc fájl Sheet1 lapján található FormA nevű űrlapot kívánja aktiválni. Először a Document szolgáltatás és a ThisComponent segítségével hozzáfér a dokumentumhoz, majd aktiválja az űrlapot.


     'Gets hold of the form that will be activated
     Dim oDoc as Object, myForm as Object
     Set oDoc = CreateScriptService("Document", ThisComponent)
     

Set myForm = oDoc.Forms("Sheet1", "FormA")

'Aktiválja az űrlapot myForm.Activate()
A Python nyelvben

     doc = CreateScriptService('Document', XSCRIPTCONTEXT.getDocument())
     form = doc.Forms('Sheet1', 'FormA')
     form.Activate()
   
note

ThisComponent applies to Calc and Writer documents. For Base documents use ThisDataBaseDocument.


CloseFormDocument

Closes the form document containing the actual Form instance. The Form instance is disposed.

Szintaxis:

svc.CloseFormDocument(): bool

Példa:


      myForm.CloseFormDocument() ' Basic
   
A Python nyelvben

      form.CloseFormDocument()  # Python
   
note

This method only closes form documents located in Base documents. If the form is stored in a Writer or Calc document, calling CloseFormDocument will have no effect.


Controls

The value returned by the Controls method depends on the arguments provided:

Szintaxis:

svc.Controls(opt controlname: str): any

Paraméterek:

controlname : A valid control name as a case-sensitive string. If absent, the list of control names is returned as a zero-based array.

Példa:


      Dim myForm As Object, myList As Variant, myControl As Object
      Set myForm = myDoc.Forms("myForm")
      myList = myform.Controls()
      Set myControl = myform.Controls("myTextBox") ' SFDocuments.FormControl
   
A Python nyelvben

      form = doc.Forms('myForm')
      form_names = form.Controls()
      form_control = form.Controls('myTextBox')  # SFDocuments.FormControl
   

GetDatabase

Return a SFDatabases.Database instance giving access to the execution of SQL commands on the database the current form is connected to and/or that is stored in the current Base document.

Each form has its own database connection, except in Base documents where they all share the same connection.

Szintaxis:

svc.GetDatabase(opt user: str, opt password: str): svc

Paraméterek:

user, password: The login optional parameters (Default = "").

Példa:


      Dim myDb As Object ' SFDatabases.Database
      Set myDb = oForm.GetDatabase()
   
A Python nyelvben

      db = form.GetDatabase()  # SFDatabases.Database
   

MoveFirst

The form cursor is positioned on the first record. Returns True if successful.

Szintaxis:

svc.MoveFirst(): bool

Példa:


      myForm.MoveFirst() ' Basic
   
A Python nyelvben

      form.MoveFirst()  # Python
   

MoveLast

The form cursor is positioned on the last record. Returns True if successful.

Szintaxis:

svc.MoveLast(): bool

Példa:


      myForm.MoveLast() ' Basic
   
A Python nyelvben

      form.MoveLast()  # Python
   

MoveNew

The form cursor is positioned on the new record area. Returns True if successful.

Szintaxis:

svc.MoveNew(): bool

Példa:


      myForm.MoveNew() ' Basic
   
A Python nyelvben

      form.MoveNew()  # Python
   

MoveNext

The form cursor is positioned on the next record. Returns True if successful.

Szintaxis:

svc.MoveNext(opt offset: int): bool

Paraméterek:

offset: The number of records to go forward (Default = 1).

Példa:


      myForm.MoveNext() ' Basic
   
A Python nyelvben

      form.MoveNext()  # Python
   

MovePrevious

The form cursor is positioned on the previous record. Returns True if successful.

Szintaxis:

svc.MovePrevious(opt offset: int): bool

Paraméterek:

offset: The number of records to go backwards (Default = 1).

Példa:


      myForm.MovePrevious() ' Basic
   

      form.MovePrevious()  # Python
   

Requery

Reloads the current data from the database and refreshes the form. The cursor is positioned on the first record. Returns True if successful.

Szintaxis:

svc.Requery(): bool

Példa:


      myForm.Requery() ' Basic
   
A Python nyelvben

      form.Requery()  # Python
   

Subforms

The value returned by the Subforms method depends on the arguments provided:

Szintaxis:

svc.Subforms(): str[0..*]

svc.Subforms(subform: str): svc

svc.Subforms(subform: int): svc

Paraméterek:

subform: A subform stored in the current Form class instance given by its name or index.

Ha ez az argumentum nincs megadva, a metódus a rendelkezésre álló alűrlapok listáját adja vissza nulla alapú tömbként. Ha az űrlapnak egyetlen alűrlapja van, akkor a subform = 0 értéket állíthatjuk be, hogy hozzáférjünk ahhoz.

Példa:


      Dim myForm As Object, myList As Variant, mySubform As Object
      myList = myform.Subforms()
      Set mySubform = myForm.Subforms("mySubform") ' SFDocuments.Form
   
A Python nyelvben

      subform_names = form.Subforms()
     subform = form.Subforms('mySubform')  # SFDocuments.Form
   
warning

All ScriptForge Basic routines or identifiers that are prefixed with an underscore character "_" are reserved for internal use. They are not meant be used in Basic macros or Python scripts.


Támogasson minket!