Borrador de la Guía del
Módulo 2 Procedimientos de evaluación
2.1 Verificación de antecedentes
2.2.1 Revisiones de la cadena
2.2.1.1 Revisión de similitud de cadenas
Most production-strength PowerBuilder applications make intense use of DataWindow controls. The u_dw DataWindow control contains extensive built-in methods including:
• Functions to enable and disable DataWindow services • A function to set the Transaction object
• Events to retrieve rows for DataWindows and DropDownDataWindows • Events to control DataWindow update
• Events to control printing Integration with PFC menus
Many of the events described in this section are called automatically by menus that descend from the PFC m_master menu. For example, when you select File>Save from the menu bar, PFC calls the pfc_Save event.
Control PFC visual user object
DataWindow U_dw ListView U_lvs TreeView U_tvs RichTextEdit U_rte OleControl U_oc Tab U_tab Tab page U_tabpg
Using standard visual user objects
Enabling DataWindow
services PFC provides a variety of DataWindow services that you can use to add production-strength features to an application. Many of these services require little or no coding on your part.
v To use DataWindow services:
1 Place the u_dw DataWindow visual user object on the window. 2 Determine which DataWindow services are appropriate for the DataWindow object displayed in the u_dw-DataWindow control. 3 Enable the appropriate DataWindow services, using the u_dw
of_Setservicename functions (this example from the DataWindow control’s Constructor event enables the row selection, row management, and sort services):
this.of_SetRowSelect(TRUE) this.of_SetRowManager(TRUE) this.of_SetSort(TRUE)
4 Establish the Transaction object for the DataWindow:
this.of_SetTransObject(SQLCA)
5 Call other functions as necessary to initialize services (this example sets the row selection style, specifies the Sort dialog box style, and enables column header sorting):
this.inv_rowselect.of_SetStyle & (this.inv_rowselect.EXTENDED) this.inv_sort.of_SetStyle & (this.inv_sort.DRAGDROP)
this.inv_sort.of_SetColumnHeader(TRUE)
6 Call DataWindow service events and functions as necessary in your application’s functions and events. In many cases you don’t have to code anything to realize the service’s benefits. This example calls the
pfc_SortDlg event to display the Sort dialog box:
dw_list.Event pfc_SortDlg()
Disabling services
The u_dw Destructor event destroys enabled services automatically. In most cases you don’t destroy a service explicitly.
For specific usage information on individual DataWindow services, see “DataWindow services” on page 63.
Setting the
Transaction object As shown in the preceding example, you establish a DataWindow’s Transaction object by calling the u_dw of_SetTransObject function.
The of_SetTransObject function ensures that the passed Transaction object is valid, sets the Transaction object, and saves a reference to the Transaction object in the itr_object instance variable.
The Transaction object must be of type n_tr. When using the linkage service
For DataWindows that use the linkage service, call the n_cst_dwsrv_linkage of_SetTransObject function on the top-level DataWindow after all
DataWindows have been created and you have established the linkage chain. For more information on the linkage service, see “Linkage service” on page 71.
Retrieving rows Because many DataWindow services rely on the u_dw pfc_Retrieve event to retrieve data, it’s best to code the PowerScript Retrieve function in the u_dw pfc_Retrieve event. To retrieve rows, your code then calls the u_dw
of_Retrieve function, which calls either the pfc_Retrieve event or the n_cst_dwsrv_linkage of_Retrieve function as appropriate.
v To retrieve rows for a DataWindow:
1 Call the of_Retrieve function (this example is from a DataWindow Constructor event):
Long ll_return
ll_return = this.of_Retrieve()
2 Add code to the pfc_Retrieve event that calls the PowerScript Retrieve function, returning the return code:
Return this.Retrieve()
Retrieving rows with the linkage service
When using the linkage service to retrieve detail DataWindow rows, code the pfc_Retrieve function for the top-level DataWindow only. When using the linkage service to filter or scroll detail DataWindow rows, code the pfc_Retrieve event for all DataWindows in the linkage chain.
Using standard visual user objects
v To retrieve rows in a DropDownDataWindow:
1 Add code to the DataWindow control’s pfc_PopulateDDDW event. This code should retrieve rows for the specified DropDownDataWindow:
IF as_colname = "dept_id" THEN adwc_obj.SetTransObject(SQLCA) Return adwc_obj.Retrieve() ELSE
Return 0 END IF
2 If the DataWindow control is using no other DataWindow services, enable n_cst_dwsrv the base DataWindow service (this example is from the DataWindow control’s Constructor event):
this.of_SetBase(TRUE)
this.of_SetTransObject(SQLCA) this.of_Retrieve()
3 Call the n_cst_dwsrv of_PopulateDDDWs or of_PopulateDDDW function to update all DropDownDataWindows or a specified DropDownDataWindow:
dw_1.inv_base.of_PopulateDDDWs() // Alternatively, you could call:
// dw_1.inv_base.of_PopulateDDDW("dept_id")
Controlling
DataWindow updates
Basic DataWindow updates PFC provides two ways to update DataWindows:
• U_dw pfc_Update event Updates a single DataWindow without any logical unit of work service processing, automatically calling the n_cst_dwsrv_multitable of_Update function if the multitable update service is enabled
• W_master pfc_Save event Uses the logical unit of work service to call the u_dw of_Updatefunction for all DataWindows on the window. For non-PFC DataWindow controls, the logical unit of work service calls the PowerScript Update function
W_master is the ancestor of all PFC windows
Because w_master is the ancestor of all PFC windows, the pfc_Save event is available to all windows in your application.
v To update a single DataWindow: • Call the u_dw pfc_Update event:
IF dw_emplist.Event pfc_Update & (TRUE, TRUE) = 1 THEN
SQLCA.of_Commit() ELSE
SQLCA.of_Rollback() END IF
v To update all DataWindows on a window: • Call the w_master pfc_Save event:
Integer li_return
li_return = w_emp.Event pfc_Save() IF li_return < 0 THEN
MessageBox("Update Failed", &
"Update failed. Return code was " & + String(li_return))
ELSE
gnv_app.of_GetFrame().SetMicroHelp & ("Update succeeded")
END IF
Automatic CloseQuery processing
If any of a window’s DataWindows has pending updates and the user closes the window, PFC displays a Save Changes dialog box automatically. If the user chooses to save changes, CloseQuery processing calls the window’s pfc_Save event.
For more information on using pfc_Save, see “Using the pfc_Save process” on page 195.
Declaring nonupdatable DataWindows You can declare a DataWindow as nonupdatable, thus removing it from the pfc_Save update sequence and the PFC default CloseQuery processing.
Shared DataWindows
If your window includes DataWindows that share data, only one DataWindow control should be updatable. All others that share data should be nonupdatable.
Using standard visual user objects
v To declare a DataWindow as nonupdatable: • Call the u_dw of_SetUpdatable function:
dw_emplist.of_SetUpdateable(FALSE)
Printing DataWindows PFC provides events that allow you to print DataWindows. You can:
• Display a Print dialog box, allowing you to choose options before printing PFC uses the s_printdlgattrib structure to pass DataWindow properties to the n_cst_platform of_PrintDlg function. You can use the pfc_PrePrintDlg event to further customize the initial contents of the Print dialog box by modifying elements in the s_printdlgattrib structure.
The elements in the s_printdlgattrib structure reflect selected DataWindow Print properties (such as collate, page numbers, and number of copies). • Print a DataWindow without displaying the Print dialog box
• Display a Page Setup dialog box that allows you to specify print settings PFC uses the s_pagesetupattrib structure to pass DataWindow properties to the n_cst_platform of_PageSetupDlg function. You can use the pfc_PrePageSetupDlg event to further customize the initial contents of the Page Setup dialog box by modifying elements in the s_pagesetupdlgattrib structure.
The elements in the s_pagesetupattrib structure reflect selected DataWindow Print properties (such as margins, paper size, and orientation).
v To display the Print dialog box:
1 (Optional) Add code to the pfc_PrePrintDlg event to modify the information used by the pfc_PrintDlg function (this example provides a default for the number of copies specification):
astr_printdlg.l_copies = 1
2 Call the pfc_Print event:
dw_emp.Event pfc_Print()
v To print a DataWindow without displaying the Print dialog box: • Call the pfc_PrintImmediate event:
Comparing File>Print with the Print button
When you select File>Print from the menu bar, PFC calls the pfc_Print event. When you click the Print toolbar button, PFC calls the
pfc_PrintImmediate event.
v To display the Page Setup dialog box:
1 (Optional) Add code to the pfc_PrePageSetupDlg event to modify the information used by the pfc_PageSetupDlg function (this example specifies the initial value for the orientation specification):
astr_pagesetup.b_portraitorientation = TRUE
2 Call the pfc_PageSetup event:
dw_emp.Event pfc_PageSetup()