At the core of any sort processing is a greater than/less than comparison. The PFC sorted list and tree list objects use the n_cst_nodecompare of_Compare function to perform this comparison. By default, the n_cst_nodecompare of_Compare function performs a comparison of two nodes as follows: • Compares key values (not data values)
• Works for simple data types only (that is, all but object instances and enumerated data types)
• Returns values that the sorted list and tree list objects use to maintain an ascending sorted list
If your sorted list requires different comparison logic, you must inherit from n_cst_nodecompare and override the of_Compare function.
Custom comparison objects
If your sorted list requires different comparison logic, you need to create a descendant of n_cst_nodecompare with an overridden of_Compare function and enable that object at execution time.
v To create a customized comparison object:
1 Use the User Object painter to create a customized n_cst_nodecompare descendant.
2 In the customized n_cst_nodecompare descendant, implement a Public of_Compare function to compare key values in the two passed nodes. This function should take two arguments of type n_cst_node (passed by value) and return Integer values as follows:
• 1 The key of the second node is greater than the key of the first node • 0 The key of the second node is equal to the key of the first node • -1 The key of the second node is less than the key of the first node In this example, each passed node contains a reference to a custom class user object with state and last name instance variables to compare:
Any la_key1, la_key2
String ls_keytype1, ls_keytype2 n_cst_empinfo lnv_emp1, lnv_emp2
IF NOT IsValid(anv_node1) THEN Return -3 IF NOT IsValid(anv_node2) THEN Return -3 anv_node1.of_GetKey(la_key1)
anv_node2.of_GetKey(la_key2) IF IsNull(la_key2) THEN Return -4 ls_keytype1 = ClassName(la_key1) ls_keytype2 = ClassName(la_key2) // Check data type of node data. IF ls_keytype1 = "" THEN Return -6 IF IsNull(ls_keytype1) THEN Return -6
IF ls_keytype1 <> "n_cst_empinfo" THEN Return -6 IF ls_keytype2 = "" THEN Return -6
IF IsNull(ls_keytype2) THEN Return -6
IF ls_keytype2 <> "n_cst_empinfo" THEN Return -6 lnv_emp1 = la_key1 // Cast to n_cst_empinfo lnv_emp2 = la_key2
// First compare State.
// Additional error checking omitted.
IF lnv_emp1.is_state < lnv_emp2.is_state THEN Return -1
ELSEIF lnv_emp1.is_state > lnv_emp2.is_state THEN Return 1
ELSE // States are equal. Compare last name. IF lnv_emp1.is_lname < lnv_emp2.is_lname THEN
Return -1
ELSEIF &
lnv_emp1.is_lname > lnv_emp2.is_lname THEN Return 1
ELSE // State and lname are equal.
Return 0
END IF END IF
v To enable a customized comparison object at execution time:
1 In the object that uses PFC list processing, define an instance variable that uses your customized n_cst_nodecompare object as the data type:
n_cst_customcompare inv_customcompare
2 Create an instance of the customized comparison object and call the n_cst_list of_SetCompare function:
inv_customcompare = CREATE n_cst_customcompare inv_sortedlist.of_SetCompare(inv_customcompare)
Timing service
3 Initialize objects before adding them to the list. In the example ahead, you create an array of n_cst_empinfo objects and initialize them with last name, first name, and state.
4 Create nodes, set node values, and add them to the list as necessary:
n_cst_node lnv_node Integer li_i
FOR li_i = 1 TO UpperBound(inv_empinfo) inv_tree.of_Create(lnv_node) lnv_node.of_SetKey(inv_empinfo[li_i]) lnv_node.of_SetData(inv_empinfo[li_i]) inv_tree.of_Add(lnv_node) NEXT
Timing service
Overview The timing service works with PFC’s n_tmg Timing object to provide single and multiple timers. These timers are especially useful with standard class and custom class user objects.
PFC enables the timing service through n_tmg, n_cst_tmgsingle, and n_cst_tmgmultiple.
Using single timers Use n_cst_tmgsingle to maintain a single timer. You establish the timer by calling the of_Register function, specifying the object to be notified, the event to be notified, and the timer interval.
v To use a single timer:
1 Establish an instance variable of type n_tmg:
n_tmg itmg_timer
2 Create the instance of n_tmg:
itmg_timer = CREATE n_tmg
3 Enable the single timer service:
4 Register the object and event to be notified (the object is a window in this example):
itmg_timer.inv_single.of_Register & (this, "ue_showtimer", 15)
5 Code the event to receive notification from n_cst_tmgsingle (ue_showtimer in this example).
Using multiple timers Use n_cst_tmgmultiple to maintain multiple timers. You establish each timer by calling the of_Register function, specifying the object to be notified, the event to be notified, and the timer interval.
v To use multiple timers:
1 Establish an instance variable of type n_tmg:
n_tmg itmg_timer
2 Create the instance of n_tmg:
itmg_timer = CREATE n_tmg
3 Enable the multiple timer service:
itmg_timer.of_SetMultiple(TRUE)
4 Register the objects and events to be notified:
itmg_timer.inv_multiple.of_Register & (iw_sheet1, "ue_timer", 7) itmg_timer.inv_multiple.of_Register & (iw_sheet2, "ue_timer", 11) itmg_timer.inv_multiple.of_Register & (iw_sheet3, "ue_timer", 13)
5 Code the events to receive notification from n_cst_tmgmultiple (ue_timer in this example).
About this chapter This chapter explains how to use PFC standard visual user objects and custom visual user objects.
Contents