| Home | Previous Lesson: Triggering Events Dynamically Next Lesson: Does TriggerEvent Really Trigger an Event? |
The event/function syntax allows you to make nested event/function calls. The return value of the first event/function must be an object and it becomes the object upon which the second event/function acts.
// instance variables
// int ii_hours
// String ii_YarnType
NonVisualObject lnc_object
nc_MachineObject lnc_MachObj
Long li_Prod
lnc_MachObj = Create nc_MachineObject
lnc_object = lnc_MachObj.Function Trigger &
Dynamic of_GetObject (ii_no)
If NOT IsValid(lnc_object) Then Return -100
li_Prod =.lnc_Object.Function Trigger Dynamic of_GetProd &
(ii_hours, ii_YarnType)
If li_Prod = 0 Then
// Error handling
End If
Destroy lnc_MachObj
The above example calculates production for different type of machines; machine from different vendors and of different makes have different formulas for production calculation. Function call of_GetObject() at custom class object nc_MachineObject returns appropriate custom class object depending on the vendor and the make of the machine. The second function of_GetProd() returns production for that machine depending on the number of hours that machine ran and the type of the product.
// instance variables
// int ii_hours
// String ii_YarnType
nc_MachineObject lnc_MachObj
Long li_Prod
lnc_MachObj = Create nc_MachineObject
li_Prod = lnc_MachObj.Function Trigger Dynamic of_GetObject &
(ii_no).of_GetProd(ii_hours, ii_YarnType)
If li_Prod = 0 Then
// Error handling
End If
Destroy lnc_MachObj
The above code does the same thing as the earlier code listing, however, this code uses nested function calls. As you can see here, you can't check if the returned object by of_GetObject() is a valid object or not.
If you use DYNAMIC keyword for the first event/function from left, it would apply for all nested event/function calls. Another suggestion would be that if you want to post event/function calls, do it only for the last event/function call.
| Home | Previous Lesson: Triggering Events Dynamically Next Lesson: Does TriggerEvent Really Trigger an Event? |