PB log-data window control function 19. Describe ()

Source: Internet
Author: User

Describe ()
Function: Return the specified information about the structure of the data window control, including the datawindow object and data window.
The attribute value of other objects in the object. Each column in the data window, each header, and so on, are the same
For more information about the attributes of a group to describe its features, see Chapter 6th. The attributes of a data window object are described in the parameters of the describe () function.
You can use a string to specify a set of attributes of the value to be obtained. This function will return their values as a string.
Back
The describe () function can also be used to calculate the value expression of an expression. You can use the value of a specified row or column.
Syntax: Dwcontrol. Describe (propertylist)
Parameters: Dwcontrol data window control name
The propertylist attribute list is a string. One or more attributes or tables whose values are to be viewed
A space is used to separate the attributes of the property index window object.
Return Value string this function returns a string which corresponds to each attribute in the propertylist.
The specific value ~ N Separation
If the attribute list contains invalid items such as misspelled attribute names or wrong expressions, describe ()
The function returns an exclamation point at the position of the corresponding item! And ignore all subsequent items when a property has no value
The describe () function returns a question mark at the corresponding position?
If the value of an attribute is a question mark? Then, the describe () function returns the question mark at this position and
The question mark is usually placed in single quotation marks'
If the value of any parameter is null, The describe () function returns NULL.
Use the describe () function to understand the structure of the data window. For example, we can check the data.
What areas are available in the window? What are the data types of the columns called with band?
After the describe () function obtains the current attribute value of the data window, you can use the data window control modify ()
Modify the Function
In applications, the describe () function is often used to obtain the current SELECT statement of the data window.
For example, add a where clause to modify the sorting method.
When developers use the data window paint brush to create a data window object graphically, select
After the data source, a SELECT statement is defined as PowerBuilder when the data window object is saved.
The saved SQL select statement is not a standard SQL SELECT statement, but a SELECT statement in its own defined format.
The pbselect statement is stored together with the data window object. When the application uses the describe () function
If the application has been connected to the database when the table. select attribute value is set, the describe () function returns the SQL
If the application is not connected to the database, the describe () function returns pbselect
Statement
In the parameters of the describe () function, the general syntax for referencing data window object attributes is
Objectname. Property
For more information about data window attribute expressions, see Chapter 6th data window object attribute access method
Section
For some properties of the data window, the describe () function will return a set of values. Each value uses a Tab character.
~ For example, the following describe () Statement returns all bands currently used in the specified data window.
Name
Bandsname = dw_1.describe ("datawindow. Bands ")
Use the Tab character ~ T is used to separate the following data windows.
Differences
Header ~ Tdetail ~ Tsummary ~ Tfooter
When an application wants to view the attributes of a column, it can use the column name or column number.
Put # Before the column number. For example, if name is the 2nd Column of a data window, then the statement
Name = dw_1.describe ("name. coltype ")
And
Name = dw_1.describe ("#2. coltype ")
Equivalent
When we use the data window paint brush to create a data window object, the system automatically kills the column object and the column title object.
The name of the column listing object is usually the same as the name of the corresponding column in the database. The name of the calculated column is compute _####
It indicates that #### is the name of the four numeric Column Titles. The column Object Name and _ t constitute a table, for example, a database table.
There is a column named salary. When the data window object contains this column, the column object name is salary.
The name of the corresponding column title is salary_t
The following describes how to use the describe () function to calculate an expression.
The evaluate () function can be used as a parameter of the describe () function to calculate the value of the brush expression in the data window.
The syntax format of the evaluate () function is
Evaluate ('expression', rownumber)
Here expression is the data window paint expression rownumber that you want to calculate its value is the row number of the Data row
The paint expression calculates the value of the row based on the data of the row. In the paint expression, you can use the data window paint function.
For details about the data window paint function, see Chapter 6th data window paint function section, for example, the following statement
Returns 3rd or 0 based on the value of the salary column in The 255 rows of the data window.
Ls_ret = dw_1.describe ("evaluate ('If (salary> 100000,255, 0) ', 3 )")
In general, we use the data window control function to obtain the data values in the data window, but some data windows
For example, the lookupdisplay () function cannot be called directly in the code.
Using the evaluate () function to calculate a number becomes the only choice.
Example 1Assume that there is a data window control named dw_emp.
The names of the two columns are EMP and empname. The names of the corresponding column title objects are emp_h and empname_h, respectively.
In addition, the State is not an object in the data window. The purpose of this selection is to demonstrate the describe () function.
After executing the following code for the handler with incorrect attribute settings
String ls_request, ls_report
Ls_request = "datawindow. Bands datawindow. Objects "&
+ "Empname_h.text "&
+ "Empname_h.type EMP. Type EMP. coltype "&
+ "State. Type empname. Type empname_h.visible"
Ls_report = dw_1.describe (ls_request)
The value of the variable ls_report is
Header ~ Tdetail ~ Tsummary ~ Tfooter ~ NEMP ~ Tempname ~ Temp_h ~ Tempname_h ~ N
"Employee ~ R ~ Nname "CD ~ N text ~ N column ~ Nchar (20 )~ N!
The exclamation point in the result indicates an error in the describe () parameter, that is, the original state column.
Example 2The following statement first checks the value of the salary column before calling the getitemnumber () function.
Column data type
String ls_data_type
Integer li_rate
Ls_data_type = dw_1.describe ("salary. coltype ")
If ls_data_type = "Number" then
Li_rate = dw_1.getitemnumber (5, "salary ")
Else
... // Other processing
End if
Example 3The following code uses the column name to obtain the data type of the current column.
This must be replaced with the actual data window control name when used in the event handler elsewhere.
S = This. Describe (this. getcolumnname () + ". coltype ")
Example 4The following code snippet is part of the event handler for the scrollvertical event of the data window control.
This code snippet is used when you scroll the data window, whether by pressing the arrow or moving the scroll bar.
Set the first visible row in the data window to the current row.
S = This. Describe ("datawindow. firstrowonpage") // obtain the row number of the first visible row.
If isnumber (s) then this. setrow (INTEGER (s) // set it to the current row.
Example 5The following code uses the evaluate () function of describe () to obtain the state_code column.
Display value this column uses the drop-down data window dropdowndatawindow editing style.
After the itemchanged event occurs, the user-selected value has been put into the corresponding buffer zone for security.
The following code is placed in the User-Defined event in the data window named getdisplayvalue.
String rownumber, displayvalue

Rownumber = string (dw_1.getrow ())
Displayvalue = dw_1.describe (&
"Evaluate ('lookupdisplay (state_code )',"&
+ Rownumber + ")")
In the itemchanged event of the data window, you can write the following code to mail custom events.
Getdisplayvalue
Dw_1.postevent ("getdisplayvalue ")
Example 6The following code is part of the itemerror event handler of a data window control. Its function is
Set the value of the data item in the current error to null. Columns of other types except string type cannot be set to null strings.
In this case, the data and row in the error code that do not match the data type are the parameters of the itemerror event.
String s
S = This. Describe (this. getcolumnname () + ". coltype ")
Choose case s
Case "Number"
If trim (data) = "" then
Integer null_num
Setnull (null_num)
This. setitem (row, this. getcolumn (), null_num)
Return 3
End if
Case "date"
If trim (data) = "" then
Date null_date
Setnull (null_date)
This. setitem (row, this. getcolumn (), null_date)
Return 3
End if
... // You can increase the processing of other data types.
End choose

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.