PowerBuilder 7.0 practical skills eight (Author: Xia Xiang, 2001 at 10:33 on February 22) methods and techniques described in this article are the author by little in practice, come to share this with everyone. I hope to help or inspire you after reading this article. If there is any shortcomings in the text, it is also looking forward to the advice. Here, I will borrow. I. Implementing the Running Window, it is well known, PowerBuilder 7.0 provides graphical preview tools in previous versions, which can be easily achieved in the design phase. However, it seems that the tool is canceled, and there is no property to set, at least I have not found it. Whenever we need to adjust its X, Y value at a point when you are in the window, this is very headache. Out of helplessness, you have to be implemented. We only write these codes only in the open event of each window that needs to hit a window. To implement the automatic home of the window, we can use the function move () to be implemented. However, because the applications we have developed tend to run in different setup environments, although it is generally configured by us, we always guarantee that the setting mode of the user display will not change. Fortunately, PB provides us with environmental object Environment, which is actually a system structure, where the PB application is saved, for example, the code set, the CPU type, and the like. Of course, there will be the screen width and high of what we need. In order to get this structure we can use the function getnvironment (). The function of this function is to obtain system information about the operating system, processor, and screen. Used as follows: Environment my_system Integer li_ScreenWidth, li_ScreenHeight GetEnvironment (my_system) // get the total width and length of the screen li_ScreenWidth = PixelsToUnits (! My_system.ScreenWidth, XPixelsToUnits) li_ScreenHeight = PixelsToUnits (! My_system.ScreenHeight, XPixelsToUnits) // function PixelsToUnits ( The role is to convert the image of the screen into the unit used by PowerBuilder, as the image is usually not in square, please refer to the function manual for specific usage. Then you can use move () to achieve the window. THIS.MOVE ((li_screenwidth - this.width) / 2, & (li_screenheight - this.height) / 2) Second Information, including province, city, address, zip code. When we want to give our customers, they need to print their provinces, cities, addresses, and zips. However, this information is separately stored, ie there is a different field. At this time we can use Powerbuiler to add a calculation domain (Compute Field) to the data window to implement the combination of character fields. Now suppose the customer's province, city, address, and zip code are stored in different fields, they are province, city, address, and pc.
We have to get the format of "Zip Code Provincial City Address", such as "(214001) No. 1, Wuxi Renmin Road, Jiangsu Province." The specific implementation is as follows: 1. Add a calculation domain to the displayed position (Compute Field) ) 2, write "'(' pc ')' province city address" in its expression bar, click OK to complete. It is easy. It is necessary to remind everyone that the calculation domain can only be used to display, it cannot be modified, because it does not have a Tab property, it cannot be focused. Third, the barcode display in the data window is not very mysterious in the data window? This may be like this for those who have not contacted barcodes. In fact, it cannot be simple enough. Don't forget how we make the document look more artistic. That's right, we will use various fonts on it. Is the problem solved? The bar code is also a font, but we don't understand. We only need to replace the fonts of the fields that need to be displayed with the barcode, such as, for example, 3 of 9 codeworks, etc. Most of these fonts are free, you can go online to download, and then install it. IV. Automatic refresh technology of the data window When we prepare the application system like inventory, sales, always hope that the program can dynamically refresh the stock or sales volume, for example, refresh every 1 second. To achieve such functions, as long as we use the time interval attribute (Timer Interval) of the Data window, the data window does not refresh when the value is 0. If you want to refresh the data window at a frequency of each second, as long as the value is Set to 1000, 1000 milliseconds. We can also add a function of flicker alarms for your application. Take the inventory, the most commonly used, the program should be automatically discriminated when the stock of a cargo reaches a minimum stock, and is displayed in a warning color, usually red. At this time, we only need to write the corresponding statement in its color attribute after using the above-described method, such as in stock, in its color properties. The following code implementation "When the stock of a certain item is less than 20, the program is blinking in red" IF (Store_Num <20, & if MOD (SECOND (NOW ()), 2) <> 0, & / / / Once every second, even the number is displayed, odd white, namely the bottom color RGB (255, 255, 255), RGB (255, 0, 0)) 5. Implementing the automatic folding in the data window Sometimes the consideration of the interface is required. Some long fields are displayed, but they cannot be ensured that there will be long fields in all situations. For example, we have asked to divide it two lines when the customer address exceeds 50 characters, and customers who are not 50 characters are still displayed in the normal format, see the figure below. The specifications are as follows: 1. Select column Address to automatically fold in the data window. 2. Select the location attribute (position) and select the AutoSize Height Option 3. Select Edit Properties (EDIT) and remove the Auto Horz Scroll Option 4, select the properties AutoSize Height option in the data window. Note that it is the property that appears when you drag the item. After the setting is completed, the results of the legend will be displayed in the lower left corner preview window.
When the column automatic folding is displayed, it should also note that the system determines that the automatic folding point is based on space or punctuation, if we enter a string of string characters and there is no punctuation or empty space Even if the string is long and no longer Therefore, we must remind users to add some spaces or carriage returns when they are entered. Sixth, the compiration of color in the data window shows that you must have seen such a display, the background color of the first line record is light yellow, the background color of the second line record is white, the third line is light yellow, Four lines are white ..., push it according to next time. See below. If you want to make the displayed data, we must first know where these data is stored in the data window. Obviously, all the data in the data window is listed in the detailed belt, so it will affect all the contents in this detailed tape as long as some data properties are set in the detail tape. The specific implementation is as follows: 1. Open the data window, click Detail, note that it is a column with the "Detail" word, not where it stores the data. Click on its mouse to appear up and down small arrows. 2. Select General Properties, click on a small button next to the color properties (color). 3. Enter IF in the expression column (GetRow (), 2) = 0, RGB (255, 255, 255)) // RGB (255, 255, 200) , Light yellow ok, pre-column, good effect, big success. 7. When the dynamic sort of the data window is used to use the Windows resource manager, when we need to click on the type or name sort, you can click on the corresponding title bar with the mouse, and the system will be alternately sorted in ascending or descending. This depends entirely on the number of odds of the user's mouse click. Such convenient operations do not have to be used in our data window - implementation of the dynamic sorting of a column. In order to achieve the above functions, the program first needs to use a global variable (which can use the form variable relative to PB), and use it to control the sorting direction between two clicks. Because there are only two sorting directions of fields, we can use a Boolean type. This example is Boolean ib_flag.
The following code / ************************************** Program code ************************************************************************* Special ************************* / STRING LS_COLUMN, LS_SORT LS_COLUMN = this.getObjecttPointer () // Get the object name LS_COLUMN = Left of the mouse Press position (LS_COLUMN, LEN (LS_COLUMN) - 2) // Get column header name if not lors (LS_COLUMN, 2)) = "_t" Then Return // If not the default column header, that is, ending or The mouse did not point at the column header, exiting LS_COLUMN = Left (Ls_Column, Len (Ls_Column) - 2) // "_T" to the end of the column title, get a valid column title name / / Switching IB_FLAG in ascending and descending order THEN LS_SORT = LS_COLUMN "A" // Assembly ELSE LS_SORT = LS_COLUMN "D" // Descendment END IB_FLAG = NOT IB_FLAG / / For the next sort preparation ls_sort = ls_sort this.sert (ls_sort) this.Sort () / *****************************End******************** ********** / Note: The dynamic sorting of the columns in the data window described here is premised on the system default column header name, that is, the column name in the title bar is ended with "_t". If you have a designer named column header, you only need to add a conditional branch, how to implement it, please reader. 8. Setting the system time When developing an application software with a data server, sometimes in order to keep all the computers to remain the same, or close to the same, mainly to avoid the time difference in the data entry, usually we will be at the client. Setting up local time to the server before using the application. This ensures that the input data has high correctness. That is, the setting of the system time is to be implemented. Here is the process of implementation. This program is a Boolean Boolean to use the external function setsystemTime () to implement system time settings. Check out that the reference manual will find that the function needs a data type indicating the system time structure as a parameter. The definition of this structure is as follows: struct _systemtime {Int Iyear; Int iMonth; Int iDayofweek; int iDay; int ire; int iMinute; INT ISECOND; int rt imilliseconds; // millisecond} str_systemTIMT; To use external functions in the program, first need to perform The external function declaration can be declared in the global external function declaration area or the local external function area according to the range of use of the function. The specific declaration is as follows: Function Boolean SetsystemTime (STR_SYSTEMTIME STR_MYTIME) Library "kernel32.dll" can be used after the declaration.