Skip to content

OnChange - dbCheckBoxDS

Called whenever the value of is changed either by the user (a keypress or mouse event) or by an explicit set value message

Type: Event

Syntax

Procedure OnChange

Description

Checkbox class

This event is called when the user clicks on the checkbox (or presses the spacebar while the focus in on the checkbox). It is also called during find and clear operations.

You can use it to do whatever you need to do with the checkbox. If any database operations are to be carried out as a result of the user selecting or clearing the checkbox, this should be done only if Operation_Mode = Mode_Waiting.

For example, if you have a checkbox that shows "Create CSV file" and the user ticks the checkbox, you can enable or disable a form object in which the user can enter the name of the file to be used.

Object oCreateCSVCheckbox Is A Checkbox
    Set Location To 10 10
    Set Label To "Create CSV file"

    Procedure OnChange
        Boolean bChecked

        Get Checked_State To bChecked
        Set Enabled_State Of oCSVFileNameForm To bChecked
    End_Procedure
End_Object

dbCheckboxDS class

The OnChange event is not used often in objects of this class. The object is connected to a table.column and the state will be stored in the record. There is not much need to react on OnChange itself although it can be very application specific.

Object Customer_Status is a dbCheckBox
    Entry_Item Customer.Status
    Set Label to "Active Customer"
    Set Size to 13 69
    Set Location to 6 110

    Procedure OnChange
        Boolean bChecked
        String sText

        Get Checked_State to bChecked
        If (bChecked) Begin
            Move (SFormat ("Made active at: %1", CurrentDateTime ())) to sText
        End
        Else Begin
            Move (SFormat ("Made INactive at: %1", CurrentDateTime ())) to sText
        End
        Set Field_Changed_Value of Customer_DD Field Customer.Note to sText
    End_Procedure
End_Object

RadioButton class

This event takes place if you select a different radio inside the same radio container class (dbRadioGroup, RadioGroup, dbRadioContainer, RadioContainer). The message is sent to the object that is selected and to the object that is deselected (in that order). Inside OnChange, you can test on Select_State.

While you can use this OnChange event, the use of a shared event named Notify_Select_State is more efficient, because you can code your reponse for a radio change only once in a central location.

So instead of coding:

Object oOutputToRadioGroup is a RadioGroup
    Set Location to 55 55
    Set Size to 54 77
    Set Label to "Output to:"

    Object oWindowRadio is a Radio
        Set Label to "Window"
        Set Size to 10 61
        Set Location to 10 5

        Procedure OnChange
            Boolean bSelected

            Forward Send Onchange

            Get Select_State To bSelected
            If (bSelected) Begin
                Set peOutputDestination Of oCrystalReport To PRINT_TO_WINDOW
            End
        End_Procedure
    End_Object

    Object oFileRadio is a Radio
        Set Label to "File"
        Set Size to 10 61
        Set Location to 25 5

        Procedure OnChange
            Boolean bSelected

            Forward Send Onchange

            Get Select_State To bSelected
            If (bSelected) Begin
                Set peOutputDestination Of oCrystalReport To PRINT_TO_FILE
            End
        End_Procedure
    End_Object

    Object oPrinterRadio is a Radio
        Set Label to "Printer"
        Set Size to 10 61
        Set Location to 40 5

        Procedure OnChange
            Boolean bSelected

            Forward Send Onchange

            Get Select_State To bSelected
            If (bSelected) Begin
                Set peOutputDestination Of oCrystalReport To PRINT_TO_PRINTER
            End
        End_Procedure
    End_Object
End_Object

You may choose to code:

Object oOutputToRadioGroup is a RadioGroup
    Set Location to 55 55
    Set Size to 54 77
    Set Label to "Output to:"

    Object oWindowRadio is a Radio
        Set Label to "Window"
        Set Size to 10 61
        Set Location to 10 5
    End_Object

    Object oFileRadio is a Radio
        Set Label to "File"
        Set Size to 10 61
        Set Location to 25 5
    End_Object

    Object oPrinterRadio is a Radio
        Set Label to "Printer"
        Set Size to 10 61
        Set Location to 40 5
    End_Object

    Procedure Notify_Select_State Integer iToItem Integer iFromItem
        Forward Send Notify_Select_State iToItem iFromItem

        Case Begin
            Case (iToItem = 0)
                Set peOutputDestination Of oCrystalReport To PRINT_TO_WINDOW
                Case Break
            Case (iToItem = 1)
                Set peOutputDestination Of oCrystalReport To PRINT_TO_FILE
                Case Break
            Case (iToItem = 2)
                Set peOutputDestination Of oCrystalReport To PRINT_TO_PRINTER
                Case Break
        Case End
    End_Procedure // Notify_Select_State
End_Object