LibreOffice 25.2 Súgó
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:
Open and activate forms.
Navigate through records shown by the form.
Get access to the controls inside the form.
Get access to subforms of a parent form.
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.
The SFDocuments.Form service is closely related to the SFDocuments.FormControl service.
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 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)
  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.
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.
To invoke the SFDocuments.Form service refer to the methods Forms(), FormDocuments() and OpenFormDocument() of the SFDocuments.Document service
Before using the Form service the ScriptForge library needs to be loaded or imported:
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")
   
     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)
   
     my_form = doc.Forms(0)
   If you try to access a FormDocument that is currently opened in Design Mode an exception will be raised.
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')
   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)
   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')
   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
   
     def OnEvent(event: uno):
         form = CreateScriptService('SFDocuments.FormEvent', event)
         pass
   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.
| 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 | The UNO object representing interactions with the form. Refer to XForm and DataForm in the API documentation for detailed information. | 
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 | 
To learn more about URI strings, refer to the Scripting Framework URI Specification.
| List of methods in the Form service | ||
|---|---|---|
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:
In Writer documents: Sets the focus on that document.
In Calc documents: Sets the focus on the sheet to which the form belongs.
In Base documents: Sets the focus on the FormDocument the Form refers to.
svc.Activate(): bool
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()
   
     doc = CreateScriptService('Document', XSCRIPTCONTEXT.getDocument())
     form = doc.Forms('Sheet1', 'FormA')
     form.Activate()
   ThisComponent applies to Calc and Writer documents. For Base documents use ThisDataBaseDocument.
This method is deprecated, use ScriptForge.FormDocument.CloseDocument method instead.
Closes the form document containing the actual Form instance. The Form instance is disposed.
svc.CloseFormDocument(): bool
      myForm.CloseFormDocument() ' Basic
   
      form.CloseFormDocument()  # Python
   The value returned by the Controls method depends on the arguments provided:
If the method is called without arguments, then it returns the list of the controls contained in the form. Be aware that the returned list does not contain any subform controls.
If the optional ControlName argument is provided, the method returns a FormControl class instance referring to the specified control.
svc.Controls(opt controlname: str): any
controlname : A valid control name as a case-sensitive string. If absent, the list of control names is returned as a zero-based array.
      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
   
      form = doc.Forms('myForm')
      form_names = form.Controls()
      form_control = form.Controls('myTextBox')  # SFDocuments.FormControl
   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.
svc.GetDatabase(opt user: str, opt password: str): svc
user, password: The login optional parameters (Default = "").
      Dim myDb As Object ' SFDatabases.Database
      Set myDb = oForm.GetDatabase()
   
      db = form.GetDatabase()  # SFDatabases.Database
   The form cursor is positioned on the first record. Returns True if successful.
svc.MoveFirst(): bool
      myForm.MoveFirst() ' Basic
   
      form.MoveFirst()  # Python
   The form cursor is positioned on the last record. Returns True if successful.
svc.MoveLast(): bool
      myForm.MoveLast() ' Basic
   
      form.MoveLast()  # Python
   The form cursor is positioned on the new record area. Returns True if successful.
svc.MoveNew(): bool
      myForm.MoveNew() ' Basic
   
      form.MoveNew()  # Python
   The form cursor is positioned on the next record. Returns True if successful.
svc.MoveNext(opt offset: int): bool
offset: The number of records to go forward (Default = 1).
      myForm.MoveNext() ' Basic
   
      form.MoveNext()  # Python
   The form cursor is positioned on the previous record. Returns True if successful.
svc.MovePrevious(opt offset: int): bool
offset: The number of records to go backwards (Default = 1).
      myForm.MovePrevious() ' Basic
   
      form.MovePrevious()  # Python
   Reloads the current data from the database and refreshes the form. The cursor is positioned on the first record. Returns True if successful.
svc.Requery(): bool
      myForm.Requery() ' Basic
   
      form.Requery()  # Python
   The value returned by the Subforms method depends on the arguments provided:
If the method is called without any arguments, then it returns the list of subforms contained in the current form or subform instance.
If the optional subform argument is provided, the method returns a new SFDocuments.Form instance based on the specified form/subform name or index.
svc.Subforms(): str[0..*]
svc.Subforms(subform: str): svc
svc.Subforms(subform: int): svc
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.
      Dim myForm As Object, myList As Variant, mySubform As Object
      myList = myform.Subforms()
      Set mySubform = myForm.Subforms("mySubform") ' SFDocuments.Form
   
      subform_names = form.Subforms()
     subform = form.Subforms('mySubform')  # SFDocuments.Form