Improve the robustness of PB programs

Source: Internet
Author: User
Tags new features valid

Author: Xingda Computer technology company (www.study01job.com) Guo Baoli

First, the Safe application software

In the development of application software, one of the important factors is to provide users with a safe working environment, there should be no "mines" in the software, and the system should give the appropriate prompt when the user will do destructive and difficult to recover the operation. Only when users are fully confident that the software is safe will they be willing to use it, and they will be able to use it confidently to explore the new features provided by the software more efficiently.

Second, what is the safety of the application

The most important, but also the least easy to implement is to exclude errors that may cause the application to terminate abnormally. In any case, the end user should not see the application of a protective error to exit the system, this error is most likely to make users lose confidence in the software. Because this means that the user wants to break the train of thought, and time and effort to log on again, and the operations that have been done will be lost because they are not saved. Of course, there are many reasons for the termination of the system, may be the network, hardware, system software or PowerBuilder itself, but the developer should be as comprehensive as possible to consider the various potential problems, so that the possibility of minimizing errors. In particular, software developed using PowerBuilder is often a protective error, but developers can not complain, but to do more testing, choose the most insurance method to achieve the same function.

In addition, when using PowerBuilder programming, another common cause of abnormal termination is due to the programmer's own reasons, that is, the variable join lag problem, that is, to define a valid object class at compile time, but not to create an instance of it at run time or to log out of the instance ( Destroy); If a piece of code references this object, the system cannot find an instance of it in memory, causing the application to terminate. So, when referring to a variable, you should first check whether it has an instance, for example, if you refer to an object in another window in one window, you should first detect whether it has created an instance before executing the code.

In the following example, the Win_a window object might not have been created while the code was executing, so the IsValid function should be checked for validity before execution:

If IsValid (win_a) Then

Close (win_a)

End If

Third, the use of data window should pay attention to the problems

PowerBuilder code will refer to columns in many data windows, and the method used to refer to this column can be either a column name or a column number. The column number refers to the order in which this data window is arranged in the SELECT statement, and if you are accustomed to referencing a column with the column number, be aware that some columns may be moved or deleted in the SELECT statement of the Data window, and if the programmer cannot remember all the code that references the Data window, It is possible that the data type mismatch error occurs. This type of error can be avoided by using a column name, but the string used here at compile time does not verify that the reference is correct, and only at run time can the system find that the string used does not exist in the data window and prompts for an error and exits the application PowerBuilder. This error is generally difficult to discover, and an effective method is to use Object Browser to clip as much as possible to reduce typos.

A secure environment should also be careful to avoid inadvertently typing invalid data. Under the GUI, there are many controls that can restrict the type of user input in a very friendly way. For example, a multiple-selection box has only two choices, so when the user has only two possibilities to make a choice, the control can be used, eliminating the hassle of additional programming for input validation. When more options are possible, a single button is available, and each option is valid and the user cannot enter any of the invalid options. By the same token, using standard controls such as Listbox,dropdowndatawindow and Dropdownlistbox can effectively avoid invalid user input without additional programming for validation. At the same time can avoid users at one input point repeatedly do input attempts and delay a lot of time.

In an application system, developers should avoid users making unauthorized or meaningless operations, in Powerbu-ilder objects such as menus and buttons have the enabled and visible properties, Therefore, actions that the user is not authorized or cannot do should change the properties of the corresponding object to disabled and invisible. For example, if you have a data Entry window and a Delete button in one window, the Delete button is invalid when you edit a new record, so the button's property should be disabled.

When the state of a window changes, you should change both properties of the control or menu item at any time.

When an object is invalid, it is a matter of personal habit to use the disabled property of the control or the Invisible property. Generally, you should use the Invisible property when a menu item or control is always invalid. For example, a user opens a window with a Delete button, but the user does not have delete permission, and the button should be invisible, and if the user has permission to delete, the deletion cannot be performed except in the current state. , such as editing a new record, when the button should be set to disabled.

Data window is a single Encapsulated object, when you do not want the user to enter a column, the entire data window can not be set to disabled, but should use other methods, generally speaking, there are the following three ways.

First, set the tab order for the column to 0 so that the user will not be able to press the TAB key or focus on the column with the mouse. If this method is used, the original tab order value should be stored in an instance variable so that it can be recovered if needed.

Second, set the display only or protect property of the column to True. When these two properties are set to True, the column can be focused (as long as the tab order is not 0), and the user can also select some text on the column and scroll horizontally and vertically, except that the value of the column cannot be modified. This method can be used if a large number of lines of text in a database can only be displayed but cannot be modified, but note that the tab order of the column cannot be 0, which preserves the user's right to copy part of the content if necessary.

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.