SFDocuments.FormControl service

The FormControl service provides access to the controls that belong to a form, a subform or a table control of a FormDocument. Each instance of the FormControl service refers to a single control in the form. This service allows users to:

To use the FormControl service in a particular form, subform or table control, all controls must have unique names.

warning

Radio buttons that share the same group name must also have unique control names.


The main purpose of the FormControl service is setting and getting the properties and values displayed by the controls in a form.

All controls have a Value property. However, its contents will vary according to the control type. For more information, read The Value Property below.

It is also possible to format the controls via the XControlModel and XControlView properties.

tip

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


Invocació del servei

Abans d'utilitzar el servei FormControl, cal carregar o importar la biblioteca ScriptForge:

note

• Per a carregar macros BASIC cal fer servir la biblioteca ScriptForge mitjançant aquesta expressió:
GlobalScope.BasicLibraries.loadLibrary("ScriptForge")

• Els scripts Python requereixen una importació del mòdul scriptforge:
from scriptforge import CreateScriptService


The FormControl service is invoked from an existing Form service instance through its Controls method.


      Dim oDoc as Object, myForm As Object, myControl As Object
      Set oDoc = CreateScriptService("SFDocuments.Document", ThisDataBaseDocument)
      Set myForm = oDoc.Forms("formDocumentName", "formName") ' SFDocuments.Form
      Set myControl = myForm.Controls("myTextBox") ' SFDocuments.FormControl
      myControl.Value = "Current time = " & Now()
   
En Python

      

from scriptforge import CreateScriptService

from time import localtime, strftime bas = CreateScriptService('ScriptForge.Basic')

doc = CreateScriptService('SFDocuments.Document', bas.ThisDatabaseDocument)

form = doc.Forms('formDocumentName', 'formName') # SFDocuments.Form

control = form.Controls('myTextBox') # SFDocuments.FormControl

control.Value = 'Current Time = ' + strftime("%a, %d %b %Y %H:%M:%S", localtime())
tip

To learn more about how to open a FormDocument and get access to its forms, refer to the SFDocuments.Form service help page.


Alternatively a FormControl instance can be retrieved via the SFDocuments.FormEvent service, which returns the SFDocuments.FormControl class instance that triggered the event.


      Sub OnEvent(ByRef poEvent As Object)
          Dim oControl As Object
          Set oControl = CreateScriptService("SFDocuments.FormEvent", poEvent)
          ' oControl now represents the instance of the FormControl class that triggered the current event
          ' ...
      End Sub
   
En Python

      def onEvent(event: uno):
          control = CreateScriptService('SfDocuments.FormEvent', event)
   

Note that in previous examples, the prefix "SFDocuments." may be omitted.

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.


Control types

The FormControl service is available for the following control types:

Button
CheckBox
ComboBox
CurrencyField
DateField
FileControl
FixedText
FormattedField

GroupBox
HiddenControl
ImageButton
ImageControl
ListBox
NavigationBar
NumericField

PatternField
RadioButton
ScrollBar
SpinButton
TableControl
TextField
TimeField


Propietats

Nom

Només de lectura

Tipus

S'aplica a

Descripció

Action

No

String

Button

Specifies the action triggered when the button is clicked. Accepted values are: none, submitForm, resetForm, refreshForm, moveToFirst, moveToLast, moveToNext, moveToPrev, saveRecord, moveToNew, deleteRecord, undoRecord.

Caption

No

String

Button, CheckBox, FixedText, GroupBox, RadioButton

Specifies the text displayed by the control.

ControlSource

String

CheckBox, ComboBox, CurrencyField, DateField, FormattedField, ImageControl, ListBox, NumericField, PatternField, RadioButton, TextField, TimeField

Specifies the rowset field mapped onto the current control.

ControlType

String

Tot

Un dels tipus de controls mostrats a dalt.

Default

No

Boolean

Button

Specifies whether a command button is the default OK button.

DefaultValue

No

Variant

CheckBox, ComboBox, CurrencyField, DateField, FileControl, FormattedField, ListBox, NumericField, PatternField, RadioButton, SpinButton, TextField, TimeField

Specifies the default value used to initialize a control in a new record.

Enabled

No

Boolean

Tot (tret del HiddenControl)

Specifies if the control is accessible with the cursor.

Format

No

String

DateField, TimeField, FormattedField (read-only)

Specifies the format used to display dates and times. It must be one of following strings:

For dates: "Standard (short)", "Standard (short YY)", "Standard (short YYYY)", "Standard (long)", "DD/MM/YY", "MM/DD/YY", "YY/MM/DD", "DD/MM/YYYY", "MM/DD/YYYY" , "YYYY/MM/DD", "YY-MM-DD", "YYYY-MM-DD".

For times: "24h short", "24h long", "12h short", "12h long".

ListCount

Long

ComboBox, ListBox

Returns the number of rows in a ListBox or a ComboBox.

ListIndex

No

Long

ComboBox, ListBox

Specifies which item is selected in a ListBox or ComboBox. In case of multiple selection, the index of the first item is returned or only one item is set.

ListSource

No

Variant

ComboBox, ListBox

Specifies the data contained in a ComboBox or a ListBox as a zero-based array of string values.

Combine