Window usage tips series of articles-collaboration between windows (I)

Source: Internet
Author: User

Data transmission when the window is opened or closed

In an application, sometimes a task is divided into several parts, and multiple windows are used for coordination. Therefore, these windows need to be well matched. For example, when retrieving a large volume of data, you can provide a small window for users to stop data retrieval at any time and display the retrieval progress in this small window. If a brief description about the employee is displayed in a window, the details of the employee can be displayed when you double-click the employee data. These examples all involve window collaboration. This section describes related functions and techniques.

There are several possible scenarios for window collaboration:

L complementary collaboration: provides more detailed information from the window than the main window, and supplements the information of the main window.

L controlled collaboration: controls the progress of the main window from the window. It usually provides the slave window with control function when the main window completes operations that require a long time.

L equal collaboration: a task is divided into several parts, and different parts are completed in different windows. During execution, you may need to refer to the intermediate results of each task, so they should be able to interact.

The above situations may be encountered in the actual application software development process. The following is a typical example.
1. Data Transmission when the window is opened or closed

Data transmission when a window is opened or closed is a basic and important window collaboration method. You can use two functions and one object to do this. The OpenWithParm and CloseWithReturn functions are used to open the window with parameters and close the window with parameters respectively. The parameters passed by these two functions are saved using the member variables of the object Message. You can use them to build window collaboration in multiple forms.

The function OpenWithParm has the function of Open function and can pass parameters to the window to be opened. The syntax of this function is as follows:

OpenWithParm (windowvar, parameter {, parent })

Windowvar is the name of the window to be opened. It can be the window defined in the window drawing board or the window variable defined in the script. parameter is the parameter to be passed and can only be a string, numeric or powerobject type. This parameter is passed to the window to be opened in the member variable of message based on the type. parent is a name of the window that has been opened, the window must be the parent window of the windowvar window. If the function is successfully executed, 1 is returned. Otherwise,-1 is returned. If any parameter is null, return null. Below are some examples of window opening by passing parameters.

The following script opens the w_employee window and passes "James Newton" to the window:

Openwithparm (w_employee, "James Newton ")

In the doubleclicked event in the data window, the following script passes the employee ID card number in the Data row clicked by the user to the w_detail window:

String ls_no

If row <1 then return // the user clicks not a data row

Ls_no = getitemstring (row, "no") // obtain the ID card number

If not isnull (ls_no) and Len (ls_no)> 0 then

OpenWithParm (w_detail, ls_no)

End If

The above script first checks whether the data row you click is valid, and uses the parameter row in the DoubleClicked event to determine whether it is greater than 0. If it is greater than 0, the user clicks a valid data row. Then, read the user and click the employee ID card number in the Data row, and pass the ID card number to the w_detail window. In the w_detail window, you can retrieve the employee details whose ID card number is equal to this parameter, which requires reading the passed parameters.

Object Message is a global variable of the structure type and has many member variables. When passing parameters, three member variables are used to read the transmitted data. They are:

L Message. DoubleParm: used to transmit Numeric-type data.

L Message. PowerObjectParm: this variable is used to transmit data of the PowerObject object type, such as data windows, buttons, list boxes, and user-defined structures.

L Message. StringParm: used to transmit String-type data.

When the OpenWithParm function is used to open the window, you should read the passed parameters before performing other operations to avoid modifying the member variables in the Message by other operations. For example, after you double-click the data window to open the w_detail window, write the following script in the w_detail window:

String ls_no

Ls_no = mesasge. stringparm // read the passed parameters

Dw_1.settransobject (sqlca)

Dw_1.retrieve (ls_no) // retrieve data with the ls_no Parameter

When setting the toolbar in the MDI window, we mentioned that when calling the universal toolbar setting module, the function openwithparm (parentwindow) is used in the clicked event of the menu item) pass the current MDI window as a parameter. Write the following script in the open event of the general toolbar setting module:

Iw_window = message. powerobjectparm

... // Other processing

Here, iw_window is an instance variable of the window type, because iw_window is used in many places in the window, so it should be defined as an instance variable.

The function closewithreturn is used to close the specified window and return parameters. The syntax format of this function is:

Closewithreturn (windowname, returnvalue)

Here, windowname is the name of the window to be closed, usually the name of the window where the script is located; Returnvalue is the value to be returned, which is exactly the same as the OpenWithParm function. If the function is correctly executed, 1 is returned. Otherwise,-1 is returned. If the input parameter is NULL, NULL is returned.

It should be noted that as long as the window is response type, using this function can effectively pass the parameter; this window does not have to be opened with OpenWithParm. You can read the passed parameters in the response window. For example, in the following example, the window w_data contains the buttons "retrieve student data", "retrieve instructor data", and a data window dw_1; when you click "retrieve student data" or "retrieve instructor data", the response window w_parm is displayed. In this window, enter the name of the student or instructor to be retrieved, click the "OK" button on w_parm in the window, and return to the w_data window to retrieve data using user input parameters.

Write the following script in the Clicked event of the w_data button "retrieving student data" in the window:

String ls_name

OpenWithParm (w_parm, "student") // open the w_parm window.

Ls_name = Message. StringParm // disable w_parm and continue executing

If Len (ls_name)> 0 Then Dw_1.Retrieve (ls_name)

Write the following script in the Clicked event of the "retrieve instructor data" button:

String ls_name

OpenWithParm (w_parm, "teacher") // open the w_parm window.

Ls_name = Message. StringParm // disable w_parm and continue executing

If Len (ls_name)> 0 Then Dw_1.Retrieve (ls_name)

Write the script in the w_parm Open event in the window:

If message. StringParm = "student" Then

St_1.text = "enter the name of the student to be searched :"

Else

St_1.text = "enter the name of the instructor you want to search :"

End If

Write the following script in the Clicked event of the "OK" button in the w_parm window:

If Len (Trim (sle_1.text) <= 0 Then

Beep (2)

MessageBox ("prompt", "Enter content in the edit box! ", STopSign !)

Else

CloseWithReturn (Parent, sle_1.Text)

End If

Write the following script in the Clicked event of the cancel button in the w_parm window:

Closewithreturn (parent ,"")

In short, when using the closewithreturn function, you must note that only when the closed window is of the response type can the return parameters be effectively obtained.

In addition, in some cases, you must directly modify the value of the message member variable to return the correct value. For example, in a data window, it is often necessary to judge whether the data has been modified in the closequery event of the window; if the data has been modified, it is saved directly, and then the corresponding mark of whether the data has been saved is returned. In a closequery event, the function closewithreturn cannot return the correct value. Therefore, you have to directly modify the value of the message member variable.

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.