Overriding the Base Form Methods

Overrides are used to override the inputs and outputs of the base form and to allow you to pass inputs to and from a workflow into your form code.

The three base form methods to be overridden are, in order of execution:

TransferDataIn()

This is where you write the code that sets up the user interface according to the input parameters, or any other initialization. This method is called after the input parameters have received their value, but before the form is displayed.

ValidateForm(ByRef errorMessage As String) As Boolean

This is where you write the code that validates the form after the Submit button is clicked. If there is an error, errorMessage is set to display in a dialog box, and False is returned; otherwise True is returned. This method is called after the Submit button is clicked.

TransferDataOut()

This is where you write the code that sets the values of the output parameters, according to the current state of the user interface. This method is called only after ValidateForm is returned as True.

The following sample form shows a list of radio buttons and an optional comment box:

Import.System
Imports System.Collections.Generic
Imports System.Windows
Imports System.Windows.Controls
Imports Proficy.Platform.Samples.Forms.Base

Public Class ChoicesVB
    Inherits Proficy.Platform.Samples.Forms.Base.BaseForm

#Region "Private Variables"

    Private _buttons As List(Of RadioButton)

#End Region

#Region "Overrides"
    ' This function gets called prior to displaying the form. Transfer the data 
    ' from the input parameters into the display components. 
    Public Overloads Overrides Sub TransferDataIn()
        PromptLabel.Text = _prompt
        ' Since the number of radio buttons is variable, we create the list here
        ' and add it into the empty panel in the display.
        _buttons = New List(Of RadioButton)()
        For Each label As String In _labels
            Dim button As New RadioButton()
            _buttons.Add(button)
            button.Text = label
            Dim x As New Drawing.Font("Arial Rounded MT Bold", 8)
            button.Font = x
            button.Height = 20
            button.Width = 300
            RadioButtonsPanel.Controls.Add(button)
        Next
        If _labels.Length > 0 Then
            If _default <= 0 Then
                _buttons(0).Checked = True
            ElseIf _default >= (_labels.Length - 1) Then
                _buttons(_labels.Length - 1).Checked = True
            Else
                _buttons(_default).Checked = True
            End If
        End If
        Me.CommentPanel.Visible = False
        If _commentVisible Then
            CommentPanel.Visible = True
            CommentText.Text = _comment
            CommentLabel.Text = _commentPrompt
        End If
    End Sub

    ' This function gets called prior to returning the outputs from the form. Transfer 
    ' data from the display components and set the output fields. 
    Public Overloads Overrides Sub TransferDataOut()
        For i As Integer = 0 To _labels.Length - 1
            If _buttons(i).Checked = True Then
                _selection = TryCast(_buttons(i).Text, String)
                _selectedIndex = i
                Exit For
            End If
        Next
        If _commentVisible Then
            _comment = CommentText.Text
        End If
    End Sub

    ''' <summary> 
    ''' This function gets called to validate the form prior to attempting to return parameters. 
    ''' This function gets called before TransferDataOut() 
    ''' </summary> 
    Public Overloads Overrides Function ValidateForm(ByRef errorMessage As String) As Boolean
        errorMessage = ""
        ' Initialize the output error message 
        If _buttons.Count = 0 Then
            errorMessage = "The form is invalid because there are no radio buttons."
            Return False
        End If
        If _commentVisible AndAlso (CommentText.Text.Trim().Length = 0) Then
            errorMessage = "Please enter a comment"
            CommentText.Focus()
            Return False
        End If
        Return True
    End Function
#End Region

#Region "InputParameters"

    ' These are the input parameters for the form. The values of these fields are 
    ' set automatically by the base class when this form is initialized. 
    ' The InputProperty specifies the User Readable Parameter Name and the Help Text for the 
    ' parameter that will be displayed in the UI. 

    <Global.Proficy.Platform.Samples.Forms.Base.InputProperty("Prompt", "Prompt", "Prompt for form")> _
    Protected _prompt As String = ""

    <Global.Proficy.Platform.Samples.Forms.Base.InputProperty("Labels", "Labels", "Labels for the Buttons")> _
    Protected _labels As String() = New String(-1) {}

    <Global.Proficy.Platform.Samples.Forms.Base.InputProperty("Default Index", "Default Index", "Index of Default Radio Button")> _
    Protected _default As Integer = 0

    <Global.Proficy.Platform.Samples.Forms.Base.InputProperty("Comment Visible", "Comment Visible", "If true user may enter a comment, defaults to false")> _
    Protected _commentVisible As Boolean = False

    <Global.Proficy.Platform.Samples.Forms.Base.InputProperty("Comment Prompt", "Comment Prompt", "Prompt to use for comment field")> _
    Protected _commentPrompt As String = "Comment"

#End Region

#Region "OutputParameters"

    ' These are the output parameters for the form. The values of these fields are 
    ' automatically tranferred out after TransferDataOut() is called. 

    <Global.Proficy.Platform.Samples.Forms.Base.OutputProperty("Chosen Label", "Chosen Label", "The Chosen Label")> _
    Protected _selection As String

    <Global.Proficy.Platform.Samples.Forms.Base.OutputProperty("Chosen Index", "Chosen Index", "The Chosen Index")> _
    Protected _selectedIndex As Integer

    <Global.Proficy.Platform.Samples.Forms.Base.OutputProperty("Comment", "Comment", "User provided comment")> _
    Protected _comment As String = ""

#End Region
End Class

The project must to be compiled to generate the DLL that is used to create the display that will be used to access the form within Workflow.