Use and exploration of PFC (1)

zhaozj2021-02-17  50

Database Fast Development Tools PowerBuilder starts from version 5.0 to provide a base class library PFC (Powerbuilder Foundation Class), making the application's development speed increased a big step. Since PFC is not very wide, many developers are not very well understood. The following is the problem that the experience and encounter in the process of the process I use, and shared and discussing with everyone. Everyone feels inappropriate, hoping to criticize the correct.

PFC helps have some instance code for individual standalone services, events, or functions, but almost no comprehensive introduction to the overall use. Therefore, I wrote these things, as a helpless material helped by PFC, most of them are in PFC help, is the summary and summarization of I use PFC.

Getting started with PFC

First, describe how to create a simple PFC application.

Construct a simple PFC program framework

With PFC, we have to learn to construct a simple application using PFC. We can construct our application framework based on the mode provided by PFC Help (see the For a Quick Start item in the Overview of the PFC, you can also view the PFC routine (PEAT, EXAMPLE, etc.) to construct our app. The following simple statements I usually use the PFC constructor to step:

First, create an empty application, inherit a new user object from the object n_cst_appmanager, named n_mdl_app; Secondly, according to the PFC Help Fast Model Instance Create a simple application framework, the difference is: Application Services, I am using The user object N_MDL_APP just created instead of the code of N_CST_AppManager, sets the relevant events of n_mdl_app, and see the program code of the PFC routine; Open Application object, change part of the property and code:

In Additional Properties, change 3 variables in the Variable Types page (SQLCA-> n_tr; error-> n_err; message-> n_msg) (reference PFC routine peat) Change the type and size of the default font (due to our development) as needed All the Chinese interface applications, all fonts are changed to "Song 9PT"), change the icon of the application as needed; change other properties as needed, such as displayName, microhelpdefault, etc.; In addition, I also need to change the application The code of the object's SYSTEMERROR event, I am using an erroneous trap module written by Xinli. Write a .ini file or change the registration item value as needed.

Ok, until this, a PFC application framework is completed. Try to run, you can see the running status of the frame window.

Add a workspace window

The application frame window is implemented, in order to work, we have to have a workspace window (Sheet).

Prime Minister, create a GRID type data window object, saved as D_Demo1. Then inherit a window object from the W_SHEET window, then place a user object U_DW in this window (the base ancestor object of the data window). The data object of the data window control is D_Demo1, which is created, created.

Write the following code in the OPEN event of the window:

/ / Open the Resize service

this.of_setresize (TRUE)

// Set the original size this.inv_resize.of_setorigsize (dw_demo.width dw_demo.x * 2, dw_demo.height dw_demo.x * 2)

// Register the control and method for implementing the Resize service

THIS.INV_RESIZE.OF_REGISTER (dw_demo, this.inv_resize.scalerightbottom)

// Asynchronously trigger the event, send a message using the message routing message. This message is to retrieve data

THIS.EVENT PFC_MESSAGEROUTER ('PFC_Retrieve')

Write the following code in the constructor event of the data window control:

this.of_settransobject (SQLCA) // Settings the object

this.of_setbase (true) / / Open Data Window Basic Service

this.of_setprintpreview (True) // Print preview service

this.of_setrowmanager (TRUE) // Row Management Service

this.of_selectRowSelect (TRUE) // Row Selection Service

this.of_setfind (True) / / Find Service

this.of_setsort (TRUE) // Sorting Service

this.of_setfilter (TRUE) // Filter Service

this.inv_rowselect.of_setStyle (this.inv_rowselect.exted) // Set the line selection service is advanced selection mode, support Ctrl & Shift keys

this.inv_sort.of_setStyle (this.inv_sort.dropdownListbox) // Set the Sort Service Dialog Box

this.inv_filter.of_setStyle (this.inv_filter.simple) // Setting the Dialog Box pattern for filtering services

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 display content of the filter service

Write the following code in the PFC_RETRIEVE event of the data window control:

Return this.Retrieve ()

If the window needs to save data, write the following code in the PFC_ENDTRANS event of the window:

Integer Li_TransRTN

IF AI_UPDATE_RESULTS = 1 THEN

// If you update the database success, submit a transaction

Li_Transrtn = SQLCA.OF_COMMIT ()

Else

/ / Otherwise, roll back the transaction, and prompt information

li_transrtn = SQLCA.OF_ROLLBACK ()

OF_MESSAGEBOX ('Update DB Failed', 'Tips', "Data Save Failed.', Exclamation!, OK!, 1)

END IF

// Returns the case where the event occurs, Success & Fail is the instance variable of W_Master

IF li_transrtn = 0 THEN

Return SUCCESS

Else

Return Failure

END IF

If the data of the window does not need to be saved, you should select the IB_UPDATEABLE property of the data window control to false so that after the data is changed, the shutdown window does not prompt the information similar to "Data to change, whether to save", etc.

Save the window name as W_Demo1.

Add a project on the main menu of the application, write the Clicked event code of the project: message.stringparm = 'w_demo'

Of_sendMessage ('PFC_Open')

Ok, run the app, look at the effect of running. You can view the following effects:

Right-click the data window to view the right-click menu of the data window; delete a data, then right-click the data window, select the "RESTORE" item, see the function of recovering the delete; "sort" on the window menu, " Filter "," Print Preview "," Find "," Replace "menu item, view the function of" Sort "," Filter "," Filter "," Find "," Replace ", etc. of Data Window; click on the menu [ View] [first / prior / next / last] and other menu items, view the flopping function of the data window; modify some data, close the window, see the dialog box for the prompt saved

These functions, when using PFC, simply set to set an attribute or write a statement to enable a service. If you want to make a higher requirement for a service, such as sorting service, the mode you want to change the service is changed to the drop-down list box mode by default PB drag and drop, and a line of command is required to change the service.

Improve and add more functions

If you want to add more more powerful features, such as flash screens, login windows, and more. The following is a brief introduction to adding a simple way to increase these functions. By the way, we can also add code and open services that we can add in these events. The specific problems involved will be slowly learned later.

By viewing the PFC routine PEAT code, we know that you can initialize the information of the version, company, Ini file, etc. in the Contructor event of the Application Manager object (GNV_APP) (instance variable value, which can be attribute) Setting in the window), you can turn on the required application services in the PFC_Open event of the Application Manager object, including: Application Options, Data Window Cache Services, Error Information Services, Debugging Services, Security Services, Transactions Register service, recently used object service, etc.

Second, we can add code in the PFC_PREABOUT, PFC_PRESPLASH, PFC_PRELOGONDLG events to customize the display of "login", and flash dialog box. Each of these three events has a reference type parameter. These parameters are corresponding attribute object instances, and developers can change the properties of these objects to achieve the control dialog box to display information purposes. If you do not change, you will be in accordance with the default style reality.

If you need, the PFC_IDLE, PFC_ConnectionBegin, PFC_ConnectionEND events of the Application Manager object, triggering these events in the application's corresponding events.

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:

INTEger Li_RTN

// Call the function to open the login dialog

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

// close (this)

Halt Closend IF

Add a code to handle the user's login in the PFC_Logon event of the Application Manager object. For example, it can be as follows:

INTEger Li_RTN

String ls_inifile

LS_INIFILE = this.of_getappinifile ()

If SQLCA.OF_INIT (LS_INIFILE, "Database") = -1 THEN

LI_RTN = Failure

END IF

// as_userid & as_password is the parameter passed to the event

SQLCA.OF_SETUSER (as_userid, as_password)

If SQLCA.OF_CONNECT () = -1 Then

LI_RTN = Failure

Else

GNV_APP.OF_SETUSERID (AS_USERID)

Li_RTN = SUCCESS

END IF

Return Li_RTN

In fact, in our most developed applications, the login window is tested is the list of users who store in the database, not the user authentication of the login database. Developers can change themselves as needed.

In addition, we can open the Status section service and workspace window (Sheet) management service of the frame window. To open these two services, we only need to write the corresponding code in the OPEN event of the frame window. However, the status strip of the PFC is really unconventional.

Message router

9CBS has a question to know the mechanism of the PFC message router. Here I extracted the section of the message router from the "PowerBuilder Basic Class Book Technical Details".

PFC uses a message router to handle communication between menus and windows. This customized message transfer mechanism is within all PFC menus and windows.

Although the message router can be used for communication with any object, he is usually used to pass the message from the menu to the window. The message router determines the object of the message according to a custom search algorithm.

Use the message router has the following advantages:

The script of the menu only needs to know the user event to be called without having to know the name of the current window or related control; the window does not have to retain the user events that simply call the data window. In this way, the number of user events retained by the window is reduced.

Message Router Function The message passed is actually a string, which contains the name of the user event to be activated by the control of the window or window. The message router includes built-in debug information, which provides an error message.

When the user selects a menu item, the Clicked event of the menu item calls the ruler of the menu and passes the name of the user event to be called. The OF_SENDMESSAGE function calls n_sendMessage functions of n_cst_menu, the function calls the PFC_Messager event of the window, the event calls the established user event.

According to the application is the MDI program or the SDI program, the way of_sendMessage calls the PFC_Messager user event is different, as shown:

PFC_MESSAGEROUTER User Event Call Window, Current Control, and Recent User Events Pass in Data Window, as shown in image:

The message router provides a menu and a communication mechanism between the windows. In addition to the command button in the data window, no buttons can call the PFC_MWSSSSAGEROUTER event. This is because the detailed function calls the GetFocus event to the current control, and the current control is the command button itself after a command button.

The above is taken from the "Powerbuilder Basic Class", and the Electronic Industry Press is published, Wang Meijun, etc.

The book is one of the "Powerbuilder 7.0 and Sybase Internet Technology Series" edited by Liu Hongyan.

转载请注明原文地址:https://www.9cbs.com/read-30212.html

New Post(0)