Using QuickEvents with Stored Procedures (Functions/Subroutines/Programs)

Documentation Correction:  (11 Jun 97)  The ability to stop the CLOSE event from a QuickEvent using Set_EventStatus(TRUE$) was originally planned for the 3.3 release but is not available until the 3.4 release.

 

For a variety of reasons, OpenInsight user interface developers often use stored procedures to implement event fuctionality.  The implementation is simple:  Create a stored procedure, and for each event on the form that should be handled, use the "Execute a procedure" QuickEvent to call the procedure, passing information about which event needs to be handled.  In the following example, the Activated event on the Debit_Entry form calls the Debit_Entry stored procedure passing "ACTIVATED" as the first parameter in order to tell the stored procedure which event to handle.

 

 

The stored procedure may use a case statement or a locate with an on..gosub to enact the appropriate handler.  The following example is attached at the end of the document as qe_ex1.txt:

 

function Debit_Entry(Instruction, Param)

Ret = ""

begin case

  case Instruction = "ACTIVATED"

    * code for the ACTIVATED event

  case Instruction = "OK_CLICK"

    * code for the OK button

end case

return Ret

 

In version 3.1, OpenInsight for Workgroups enabled developers to pass event parameters to the stored procedure.  For example, if the CreateParam event parameter passed to the CREATE event of the window were needed by the procedure, it can be passed using the QuickEvent as follows:

 

If you go to the CREATE event in the Form Designer's event editor, you will notice that the CreateParam parameter is the third parameter, not the first.  So why do you specify '@PARAM1'  to pass the third parameter?  Simple.  The first two parameters, CtrlEntID and CtrlClassID are pre-set.  You can pass CtrlEntID from aQuickEvent by specifying '@SELF', and you can get CtrlClassID by getting the TYPE property of CtrlEntID.  So the third event parameter is considered to be the first "real" parameter, thus '@PARAM1' passes the CreateParam parameter for the CREATE event.

 

The following example, showing how the CreateParam is passed in, is attached at the end of the document as qe_ex2.txt:

 

function Debit_Entry(Instruction, Param)

Ret = ""

begin case

  case Instruction = "CREATE"

    * CREATE event:  Param contains the CreateParam value

  case Instruction = "ACTIVATED"

    * code for the ACTIVATED event

  case Instruction = "OK_CLICK"

    * code for the OK button

end case

return Ret

 

Prior to OpenInsight for Workgroups 3.3, the only event that couldn't be handled in a stored procedure was the CLOSE event, because there was no way to tell the form that it shouldn't close.  In the 3.3 release, you can stop the form from closing from a QuickEvent by setting the event status.

 

The following example, showing how the form's Close event can be stopped before the window is destroyed, is attached at the end of the document as qe_ex3.txt:

 

function Debit_Entry(Instruction, Param)

 

declare function   Get_Property

declare subroutine Set_EventStatus

$insert Logical

 

Ret = ""

begin case

  case Instruction = "CREATE"

    * CREATE event:  Param contains the CreateParam value

  case Instruction = "ACTIVATED"

    * code for the ACTIVATED event

  case Instruction = "CLOSE"

    * if the required edit control EB_AMOUNT is not filled in, do not close

    if len(Get_Property(@window: ".EB_AMOUNT", "DEFPROP")) else

      Set_EventStatus(TRUE$)

    end

  case Instruction = "OK_CLICK"

    * code for the OK button

end case

 

return Ret

 

In case your browser has nixed the code formatting, here are the examples in text format:

{{kb0109_4.png}} {{kb0109_5.png}} {{kb0109_6.png}} 

  • kb/kb_articles/kb0109.txt
  • Last modified: 2024/01/30 13:36
  • by 127.0.0.1