How to do it...

To create a pre-event or post-event handler, follow these steps:

  1. Open the designer for the table or class that we want to add a handler for, such as the SalesTable table.
  2. Locate the method we wish to handle and right-click on it: select Copy event handler method | Pre-event handler (or Post-event handler as required). This creates a method declaration into the paste buffer.
  3. Paste the method declaration into the target class for a pre-event handler on SalesTable.Insert(), which will be as follows:
/// <summary> 
///
/// </summary>
/// <param name="args"></param>
[PreHandlerFor(tableStr(SalesTable),
tableMethodStr(SalesTable, insert))]
public static void SalesTable_Pre_insert(
XppPrePostArgs args)
{
}
  1. What we do at this point depends on the requirements; the common methods in args are as follows:

Method

Use

boolean existsArg(str)

Does the handled method have the parameter

AnyType getArThig(str)

This returns the method's parameter value using the parameter's name. It is returned as an AnyType object.

For example, if we are handling SalesTine.insert(Boolean _skipMethod = false),

we can get the value of _skipMethod using

args.getArg('_skipMethod').

There is no validation; we will use existsArg to check first. This is not an intrinsic function, and we can't cause a compilation error to highlight any runtime errors.

AnyType getArgNum(int)

This gets the handled method's parameter by using its position from the left.

AnyType getThis()

This gets the instance of the object, in our case, the current SalesTable record.

There is no compiler validation on the type, so we must check this manually. Again, we can't use intrinsic functions to force a compilation error.

AnyType getReturnValue

This is only useful on post-event handlers and gets the value the method has returned.

We would usually use this in conjunction with the setReturnValue method.

setReturnValue(AnyType)

This is only useful on post-event handlers and lets us override the value the method returns.

setArg(str, AnyType)

This allows us to set the method's parameter named in this method.

setArgNum(int, AnyType)

This allows us to set the method's parameter by its position from the left.

  1. Once done, save and close the designer.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.197.35