Skip to content

Putting It All Together

This sample shows how a simple batch process might be created. In this example, we find all records and change the value of a single field. This process would be run by sending the Run_Batch_Process message to the object.

If an error occurs, we want the process to stop. If a user presses the Cancel button, we want to verify the cancel and possibly stop the process. Note that we always shut off the status panel before getting any user input. In this case, we must temporarily remove the status panel anytime an error occurs or the cancel button is pressed.

// at top of program
Use StatPnl.pkg // creates object: Status_Panel (can be accessed via global handle ghoStatusPanel)

Object Process is a SomeClass
    Property Handle phOldErrorId // keep track of old (global) error object
    Property Boolean pbErrorFound // set true means error occurs during process

    Function Check_Stop_Process returns Boolean
        handle hStatId // use this to keep ID of Status_Panel
        Boolean bStopIt
        Move ghoStatusPanel to hStatId // object ID of status panel
        Get Check_StatusPanel of hStatId to bStopIt // check for user interrupt (cancel button)

        If (bStopIt) Begin
            // if we are to display a warning we must first shut off
            // the status panel.
            Send Stop_StatusPanel of hStatId
            Get Confirm "Continue Process" to bStopIt
            // if we did not stop the process we must restart the status panel
            If Not (bStopIt) ;
                Send Start_StatusPanel of hStatId
        End
        Function_Return bStopIt
    End_Function

    Procedure Run_Batch_Process
        handle hErrorId
        handle hStatId // use this to keep ID of Status_Panel
        Boolean bStopIt

        Set pbErrorFound to False // this will get set T if an error occurs
        Set phOldErrorId to Error_Object_Id // remember old error object
        Move Self to Error_Object_Id // make self the error object
        Move ghoStatusPanel to hStatId // object ID of status panel
        Send Initialize_StatusPanel of hStatId "Run Process" "Changing Field" ""
        Send Start_StatusPanel of hStatId
        Clear Vendor

        Repeat
            Find Gt Vendor.Id
            If not (Found) Break
            Send Update_StatusPanel of hStatId Vendor.Id
            Move "X" to Vendor.Marker
            SaveRecord Vendor
            Get pbErrorFound to bStopIt // if error occurred, we quit.
            If (bStopIt) Break
            Get Check_Stop_Process to bStopIt // if true, user canceled the process
            If (bStopIt) ;
                Break
        Loop

        Send Stop_StatusPanel of hStatId
        Get phOldErrorId to hErrorId
        Move hErrorId to Error_Object_Id // restore original error object
    End_Procedure

    Procedure Error_Report integer iErrorNumber integer iErrorLine string sErrorText
        handle hErrorId
        Send Stop_StatusPanel of ghoStatusPanel // remove panel for error
        // direct error to standard error handler
        Get phOldErrorId to hErrorId
        Send Error_Report of hErrorId iErrorNumber iErrorLine sErrorText
        Set pbErrorFound to True // indicate that an error has occurred
    End_Procedure
End_Object

If a developer wishes to create a custom panel, he/she should use cProcessStatusPanel.pkg as a template. This panel can be visually modeled and changed in any way you wish. Just save your new custom panel with a different file and object name and direct your status panel request to the new object.

If the new panel changes the interface and updates objects that are not currently defined, you want to make sure you send the message ProcessEvents after you've updated the object. This allows the object to paint when inside of a tight loop. For example, if you wanted to add a progress bar (cProgressBar), you would want to send ProcessEvents after you update the progress bar.

Procedure UpdateStatusBar
    Send DoAdvance of oProgressBar
    Send ProcessEvents
End_Procedure

Of course, if you use the standard interfaces in the status bar and your forward send these messages, this will be done for you.

See Also

Using the Status Panel