Adding event handlers
Print
- Last Updated: January 16, 2024
- 2 minute read
- OpenEdge
- Version 12.8
- Documentation
In this section you will add:
- Methods that execute when you click a button
- The method that executes when you scroll from one record to another in the data source
After adding the code, you will subscribe each button and the ProBindingSource to the appropriate method.
To add event handlers to purchaseOrderForm.cls:
- Open purchaseOrderForm.cls in the ABL Editor. (When a form is open in the Visual Designer canvas, you can open it in the ABL Editor by pressing F9 or by choosing View Source in the context menu.)
-
Add event handler methods to purchaseOrderForm.cls. Copy and paste
the following code before the
DESTRUCTORmethod to implement the event handler for bindingSource1:METHOD PRIVATE VOID OnPositionChanged (sender AS System.Object, e AS System.EventArgs ): DEF VAR pbs AS Progress.Data.BindingSource NO-UNDO. pbs = cast(sender, 'Progress.Data.BindingSource'). btnPrev:Enabled = pbs:Position GT 0 . /*Prev*/ btnFirst:Enabled = btnPrev:enabled. btnNext:Enabled = pbs:Position LT (pbs:Count - 1). /*Next*/ btnLast:Enabled = btnNext:Enabled. DELETE OBJECT e NO-ERROR. END METHOD.Copy and paste the following code before the
END CLASSstatement to implement the event handlers for the buttons:METHOD PRIVATE VOID btnFirst_Click (sender AS System.Object, e AS System.EventArgs ): bindingSource1:Position = 0. END METHOD. METHOD PRIVATE VOID btnNext_Click (sender AS System.Object, e AS System.EventArgs ): bindingSource1:Position = bindingSource1:Position + 1. END METHOD. METHOD PRIVATE VOID btnPrev_Click (sender AS System.Object, e AS System.EventArgs ): bindingSource1:Position = bindingSource1:Position - 1. END METHOD. METHOD PRIVATE VOID btnLast_Click (sender AS System.Object, e AS System.EventArgs ): bindingSource1:Position = bindingSource1:Count - 1. END METHOD. METHOD PRIVATE VOID btnSave_Click (sender AS System.Object, e AS System.EventArgs ): THIS-OBJECT:SaveRecord(). END METHOD. METHOD PRIVATE VOID btnAdd_Click (sender AS System.Object, e AS System.EventArgs ): THIS-OBJECT:AddRecord(). END METHOD. METHOD PRIVATE VOID btnDelete_Click (sender AS System.Object, e AS System.EventArgs ): THIS-OBJECT:DeleteRecord(). END METHOD. METHOD PRIVATE VOID btnCancel_Click (sender AS System.Object, e AS System.EventArgs ): THIS-OBJECT:CancelUpdate(). END METHOD.Notice that some of these methods call the methods that are prototyped in the interface file IUpdatable.cls. You will implement these interface methods in Adding the interface methods.
- Save the file and return to the Visual Designer.
-
Select each button and change the Click event in the
Events tab of the Properties view as
follows:
Button name Click value btnFirst btnFirst_Click btnPrev btnPrev_Click btnNext btnNext_Click btnLast btnLast_Click btnAdd btnAdd_Click btnDelete btnDelete_Click btnSave btnSave_Click btnCancel btnCancel_Click Note: You can double-click on a control to subscribe to the control's default event. The ABL Editor appears in a template where you can complete the code that runs when the event occurs. However, in this exercise, in which you copied and pasted pre-existing code, it is easier to subscribe to the events for each control in the Properties view after the code is pasted in the file. - Select the bindingSource1 control on the Design Canvas.
- Add onPositionChanged to the PositionChanged event in the Events tab of the Properties view.