The Database rapid development tool PowerBuilder has provided a set of basic class library PFC (PowerBuilder Foundation Class) starting with version 5.0, making application development a big step further. Because PFC is not widely used, many developers don't know much about it. Following on the process of my use of the experience and problems encountered, sorted out with you to share and explore. You feel that there is a wrong place to criticize.
PFC Help has some instance code for individual services, events, or functions, but the overall use is rarely described. Therefore, I write these things, as one of the auxiliary materials of PFC help, most of it is not in the PFC Help content, is my use PFC process summary and induction. Introduction to PFC
First, let's introduce how to create a simple PFC application.
Construct a simple PFC program framework
With PFC, we need to learn to use PFC to construct a simple application. We can construct our application framework based on the patterns provided by PFC help (see for a quick start in the PFC Help overview), or you can view the PFC routines (Peat, example, etc.) to mimic the construction of our application. Here's a brief description of the steps I usually use to build an application: First, create an empty application, inherit a new user object from the object N_cst_appmanager, and name it N_mdl_app; Based on the PFC help quick model instance to create a simple application framework, the difference is: application services, I use the user object N_mdl_app I just created instead of N_cst_appmanager,
Set the code for N_MDL_APP related events, see the program code for the PFC routine, open the application (application) object, change some of the properties and code: In additional properties, change variable Types 3 Variables in the page (sqlca->n_tr; error->n_err; Message->n_msg) (refer to the PFC routine peat) change the type and size of the default font as needed (since all fonts are changed to "Arial 9pt"), change the icon of the application as needed, and change other properties as needed. For example: DisplayName, Microhelpdefault, and so on; In addition, I also need to change the application object of the Systemerror event code, I am using a New written error trap module.
Write as needed. INI file or change the registry key value.
OK, so far, a PFC application framework is complete. Try running and you can see the running state of the frame window.
Add a workspace window
The Application Framework window is implemented, and in order to work, we have to have a workspace window (Sheet).
Prime Minister, create a grid-type Data Window object and save it as a d_demo1. It then inherits a Window object from the W_sheet window and then places a user object U_dw (the underlying ancestor object of the Data window) in this window. The data object for the Data window control is d_demo1 the Data window object that you just created.
Write the following code in the window's Open event:
Turn on the Resize service this.of_setresize (True)/Set the original size of the Resize service this.inv_Resize.of_SetOrigsize (dw_demo.width + dw_demo.x * 2, Dw_demo.height + dw_demo.y * 2)//Registration of controls and methods for implementing Resize services This.inv_Resize.of_Register (dw_demo,this.inv_ Resize.scalerightbottom)//asynchronously triggers an event, sending a message using message routing. The message is to retrieve the data this. Event Post pfc_messagerouter (' Pfc_retrieve ')
Write the following code in the constructor event of the Data window control:
This.of_settransobject (SQLCA)/Set Things object This.of_setbase (TRUE)/Open Data Window basic services This.of_setprintpreview (TRUE)// Print Preview Service This.of_setrowmanager (TRUE)//Line Management Service This.of_setrowselect (TRUE)//Line Select service This.of_setfind (TRUE)/Find service This.of_ Setsort (TRUE)//Sort service This.of_setfilter (true)/filter service This.inv_RowSelect.of_SetStyle (This.inv_RowSelect.EXTENDED)// Set row selection service for advanced selection mode, support Ctrl & SHIFT key This.inv_Sort.of_SetStyle (This.inv_Sort.DROPDOWNLISTBOX)/Set Sort Service dialog Style THIS.INV _filter.of_setstyle (This.inv_Filter.SIMPLE)/Set the Filter Service dialog style This.inv_Sort.of_SetColumnDisplayNameStyle (this.inv_ Sort.header)//Set the display content of the sort service This.inv_Filter.of_SetColumnDisplayNameStyle (This.inv_Filter.HEADER)//Set the filter service display
Write the following code in the Pfc_retrieve event of the Data window control:
return this. Retrieve ()
If the window needs to save the data, write the following code in the Pfc_endtrans event of the window:
Integer Li_transrtn
If Ai_update_results = 1 Then//If the update database succeeds, commit the transaction Li_transrtn = SQLCA. Of_commit () Else//Otherwise, roll back the transaction and prompt for information Li_transrtn = SQLCA. Of_rollback () of_messagebox (' Update DB Failed ', ' hint ', ' data save failed. ', exclamation!,ok!,1) End if//Returns the case of the event SUCCESS & failure is w_master instance variable If li_transrtn = 0 Then return successelse Re Turn Failureend If
If the window's data does not need to be saved, select false for the Data window control's Ib_updateable property, so that when data is changed, closing the window does not prompt for information like "Data to change, save," and so on.
Name the window Save as W_demo1.
Add an item to the main menu of the application and write the clicked event code for the project:
OK, run the application and see how it works. You can look at the following effects:
Using the right mouse button to click the Data window, view the right menu of the data window, delete a piece of data, right-click the Data window, select the Restore item, and look at the Restore deletion feature; Click Sort, Filter, Print Preview on the Window menu, Find, "Replace" and other menu items, look at the data window of the "sorting", "Filter", "Print Preview", "Look Up", "replace" and other functions, click the Menu [First/prior/next/last] menu items, view the Data window page paging function; Modify some of the data, close the window, and view the dialog box that prompts you to save
These functions, when using PFC, can be achieved simply by setting an attribute or writing a statement that opens a service. If you want to make a higher request for a service, such as a sort service, the mode you want to change the service is changed by the default PB drop sort to a drop-down list box, and a line of commands to change the way the service is made.
Improve and add more functionality
If you want to add more powerful features, such as splash screen, login window, and so on. Here's a quick introduction to the simple way to add these features. By the way, we can also add code and open services to these events. The specific issues involved will be gradually learned later.
By looking at the code of the PFC routine peat, we know that the version, company, INI file, and so on can be initialized in the Contructor event of the Application Manager object (Gnv_app object) (instance variable values, which are mostly set in the Properties window), can be found in the Application Manager object's Pfc_open event to open the application services that are required, including application Options services, Data window caching services, error information Services, debugging services, security services, transaction registration services, recently used Object Services, and so on.
Second, we can add code to the Pfc_preabout,pfc_presplash,pfc_prelogondlg event of the object to customize the display of "about", "login," and the splash Screen dialog box. Each of these three events has a reference parameter, which is the corresponding Property object instance where the developer can change the properties of these objects to achieve the purpose of the Control dialog box display information. If you do not change, you will follow the default style reality.
If necessary, write code in the Pfc_idle,pfc_connectionbegin, pfc_connectionend events of the Application Manager object and trigger these events in the appropriate events applied.
If you need to display the login window, you need to complete the following steps:
Call the Of_logondlg () function in the Open event of the frame window:
The integerli_rtn//call function opens the Login dialog box li_rtn= gnv_app.of_logondlg () If Li_rtn = 1 Then this. Setmicrohelp (' logon successful ') Else if Li_rtn =-1 Then MessageBox (' Logon ', ' Logon failure ' + String (LI_RTN)) End If//clo SE (this) Halt closeend If
Add code in the Pfc_logon event of the Application Manager object to handle the user's login. For example, you could be the following code:
Integerli_rtnstringls_inifilels_inifile= this.of_getappinifile () If sqlca.of_init (Ls_inifile, "DataBase") =-1 Then li _rtn= failureend If//as_userid & As_password for arguments passed to the event Sqlca.of_setuser (As_userid,as_password) If SQLCA.of_Connect () =-1 Then li_rtn= failureelse gnv_app.of_setuserid (as_userid) li_rtn= successend Ifreturnli_rtn
In fact, in most of our applications, the login window examines the list of users we have stored in the database, not the user authentication of the login database. Developers can make changes on their own as needed.
In addition, we can open the frame window's status bar service and the workspace window (Sheet) Management service. To turn on these two services, we simply write the appropriate code in the Open event of the frame window. However, PFC State bar is really passable.
Message router
CSDN has a netizen question to know the PFC message router mechanism problem, below I from the "PowerBuilder Basic Class Library technical details" a book excerpt a section of the message Router section.
PFC uses the message router to handle communication between menus and windows. This custom message-transfer mechanism is within all of the PFC menus and windows.
Although the message router can be used for any object to communicate with a window, it is often used to pass messages from a menu to a window. The message router determines the object that accepts the message based on a custom search algorithm.
Using the message router has the following advantages: The script for the menu only needs to know the user event to invoke without having to know the name of the current window or related control; The window does not have to keep those user events that simply call the data window. In this way, the number of user events that the window retains is reduced.
The message router function delivers a string that contains the name of the user event that the control of the window or window is to activate. The message router includes built-in debugging information to provide error information.
When the user selects a menu item, the clicked event of the menu item calls the Of_sendmessage function of the submenu and passes the name of the user event to invoke. The Of_sendmessage function calls the Of_sendmessage function of the N_cst_menu, which calls the window's Pfc_messagerouter event, which then invokes the user event that is formulated.
Depending on whether the application is an MDI program or an SDI program, the way that Of_sendmessage calls Pfc_messagerouter user events is different, as shown in the figure:
Pfc_messagerouter the User Event Call window, the current control, and the most recent user event passed in the Data window, as shown in figure:
The messaging router provides a mechanism for communication between menus and windows. In addition to the command buttons in the Data window, no buttons can invoke the Pfc_mwssagerouter event. This is because the verbose function calls the GetFocus event to the current control, and after a command button is actually clicked, the current control is the command button itself.
The above content is excerpted from "PowerBuilder Basic class Storehouse technical detailed explanation", the electronic industry Press publishes, Wang Meijun and so on.
The book is a member of the PowerBuilder 7.0 and Sybase Internet Technology series, edited by Liu Hongyan.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service