Two tips for window operations in Pb

Source: Internet
Author: User

Two tips for window operations in Pb

Xin Xiaohui

Powerbuilder is an application development tool with comprehensive functions and excellent performance. However, it is also a complex system with a complex structure. It is difficult to learn and master it. In my practical work, I have summarized the two window operation skills and shared them with you.

1. Find the data that matches the input data in the drop-down data window.

When we look for data from the drop-down data window, we usually need to start from the first row of the drop-down data window. If there is very little data in the drop-down data window, It is very convenient to search. However, if there is a lot of data in the drop-down data window, it will be very troublesome to use this method. If the drop-down data window has the automatic match function, the drop-down data window of the column automatically scrolls to the row where the first data that matches the input data most, and the line is displayed in high brightness. In this way, you can find the data you need in a short period of time, saving the trouble you need to find in the drop-down data window, improving the accuracy of input data and the efficiency of searching related data. To achieve this, you need to write the following code in the editchanged event of the data window control (dw-1:

// Define variables

String ls_search, ls_col_name, ls_type, ls_mach

Datawindowchild child

Long ll_count = 1

Long ll_mthrow

String ll_mthtext

Long ll_searchrow = 0

// Determine whether the current column has a drop-down data window. If not, exit the event program.

Ls_col_name = dw_1.getcolumnname ()

If dw_1.getchild (ls_col_name, child) <0 then

Return

End if

// Obtain the display columns and their types in the drop-down data window.

Ls_col_name = This. Describe (ls_col_name + ". dddw. displaycolumn ")

Ls_type = Child. Describe (ls_col_name + ". coltype ")

// Obtain the text in the input Column

Ls_search = dw_1.gettext ()

If Len (ls_search) = 0 then

Return

End if

// Find the row that best matches the input data in the drop-down data window

If ls_type = "Number" then

Do until ll_count> child. rowcount ()

Ll_mthrow = Child. getitemnumber (ll_count, ls_col_name)

If left (string (ll_mthrow), Len (ls_search) = ls_search then

Ll_searchrow = ll_count

Exit

Else

Ll_count = ll_count + 1

End if

Loop

Else

Do until ll_count> child. rowcount ()

Ll_mthtext = Child. getitemstring (ll_count, ls_col_name)

If left (FIG, Len (ls_search) = ls_search then

Ll_searchrow = ll_count

Exit

Else

Ll_count = ll_count + 1

End if

Loop

End if

If ll_searchrow> 0 then

// The selected rows in the drop-down data window are displayed in high brightness.

Child. setrow (ll_searchrow)

If ls_type = "Number" then

Ls_mach = string (child. getitemnumber (ll_searchrow, ls_col_name ))

Dw_1.setitem (dw_1.getrow (), dw_1.getcolumn (), ls_mach)

Else

Ls_mach = Child. getitemstring (ll_searchrow, ls_col_name)

Dw_1.setitem (dw_1.getrow (), dw_1.getcolumn (), ls_mach)

End if

Child. selectrow (ll_searchrow, true)

End if

Note: In a column with a drop-down data window, the "allow editing" attribute of the column must be set to true.

2. Information interaction skills between windows and user objects

In practical applications, you often need to pass the information of the window object to a user object referenced in the window, or pass the parameters of the user object to the window object. There are many methods and techniques for implementing information interaction between the two. I will introduce three methods here.

1. Directly reference object attributes

The simplest way to implement window communication with user objects is to directly reference object attributes. For example, if there is a user object control named uo_1 in the window that is associated with a custom visual user object, this custom user object has a single row editor named sle_1, you can write the following code in the window script:

Uo_1.sle_1.text = string (today ())

This method is simple, but the interfaces between windows and user objects are vague. To maintain a clear interface between user objects and windows, it is best to communicate with user objects through functions and user events.

2. Use functions to communicate between windows and user objects

To pass information from a window to a user object, first define a user object-level function for the user object in the user object descriptor. Its access permission is public. Then define the input parameters to be passed for the function. The actual values of these parameters come from the window object. After a defined user object is placed in a window, the user object-level function is called in the window script to pass the actual information value through the parameters of the user object function. In this way, the user object can process information in the window object.

For example, you can define a visual user object that contains a single-row editing control. When a user inputs a string, the entered string is transmitted to sle_1, the single-row editing control of the window.

First, define a window function wf_1 in the window descriptor, which has a parameter SF to accept strings from user objects. The function contains only one code that displays the accepted parameters in sle_1, a single-row editing control:

Sle_1.text = SF

Then define a visual user object in the user object descriptor, including a single row Edit Control sle_u1, and enter the following code in the modified event of sle_u1:

Parent. F2 (this. Text)

F2 is a user object-level function. The window function cannot be called in the control of the user object. Therefore, the user object-level function is called in the user object to pass the string to the F2 parameter, then, call the window function wf_1 in F2. The Code of user object function F2 is as follows:

Parent. Dynamic wf_1 (FF)

Note that the dynamic keyword cannot be omitted. This is because the user object descriptor cannot determine whether this function exists in the window where the user object is located. Therefore, you need to confirm the correctness of this statement at runtime.

3. Use user events to implement window-to-user object Communication

After you place a Custom User object in a window or another Custom User object, you can only write scripts for the events of the user object, but not the controls in the user object. Therefore, it is often necessary to define user events for user objects, and then write scripts for user events in the Windows descriptor, so that controls in user objects can be referenced in the window.

For example, define a visual user object, including a command button, define a user event "ue_user" for this visual user object, and write program code in the clicked event of the command button:

Parent. triggerevent ("ue_user ″)

Put this user object in a window. In the window, you can find the user event "ue_user" declared for the user object and write code for it in the following table of the select event of the script descriptor of the user object, this allows you to reference controls in user objects in a window.

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.