Usage of dynamic call types in Pb

Source: Internet
Author: User
Tags argumentlist
Usage of dynamic call types in Pb

When it comes to the dynamic call type, Let's first look at the reference methods of objects, attributes, functions, and events:

The development process of PowerBuilder 6.0 applications is actually the process of defining and using various objects. All objects have names and are differentiated by names. In powerscript, the method for accessing the attributes, functions, and events of an object is simple, that is, the dot is used as a tag. Specifically, the format of the Access Object attribute is:

Object Name. Object Attributes

For example, the statement that sends the user input content in the single row edit box sle_name to the string variable userenter can be written:

Userenter = sle_name.text

Sle_name is the name of a single row edit box object, and text is the text attribute of the single row edit box.

The format of functions and events used to access objects in the program is:

{Objectname.} {type} {calltype} {when} functionname ({argumentlist })

The components in braces can be omitted based on actual conditions. The meanings of each component are as follows:

Objectname is the object name;

The value of type is function or event, which is used to specify the access function or event. The default value is function;

Calltype is used to specify the time when PowerBuilder finds a function. Valid values:

Static (default): searches for functions during compilation. If the function does not exist, a compilation error is generated.
Dynamic: query the function when the program runs. If the function does not exist, a running error occurs.

When indicates whether the function or event is executed immediately or after the current program segment is executed. The value can be:

Trigger (default): Run now
Post: after the current program segment is executed

Functionname indicates the name of the called function or event

Argumentlist provides function or event parameters.

For example, if you want to move the input focus to sle_name in the single-row edit box, write the statement sle_name.setfocus () in the program. To execute the click event handler of the button cb_name immediately, write the statement cb_name. Event trigger clicked.

As shown above, dynamic is a dynamic call to specify a function or event. That is, when you specify a dynamic call, functions and events do not necessarily exist during compilation. You tell the compiler: Believe me, there must be a suitable function or event at runtime. For dynamic calls, PowerBuilder waits until execution to find functions or events. This gives you more programming flexibility.

Compare the following examples (excerpt ):

Currently, most popular applications provide the Undo function. In PowerBuilder, you can also use the Undo () function to implement this function. The undo () function can be used for datawindow, editmask, multilineedit, richtextedit, and singlelineedit objects. If you only perform undo operations on one object, you only need to input the following script in the Click Event of the Undo menu item: objectname. undo (), but when there are multiple objects in the window, we do not know which object to execute the Undo () operation when writing the script. How can we solve this problem? In PowerBuilder, undo () and other functions can only be used for visual objects, and all visual objects inherit from the graphicobject class of the system object. Therefore, we can define the instance variable go_object of a graphicobject object, and use the getfocus () function to determine the specific operation object at runtime. Then, use the typeof () function to determine the type of the current object, and then use the choose case statement to reference different instance variables based on different types. The Code is as follows:

Graphicobject go_object

Datawindow dw_object

Editmask em_object

Multilineedit mle_object

Richtextedit rte_object

Singlelineedit sle_object

Go_object = getfocus ()

Choose case typeof (go_object)

Case datawindow!

Dw_object = go_object

Dw_object.undo ()

Case editmask!

Em_object = go_object

Em_object.undo ()

Case multilineedit!

Mle_object = go_object

Mle_object.undo ()

Case richtextedit!

Rte_object = go_object

Rte_object.undo ()

Case singlelineedit!

Sle_object = go_object

Sle_object.undo ()

Case else

MessageBox ("error", "cannot be undone! ")

End choose

In fact, we can use the dynamic call function method to solve this problem simply, that is, to call the Undo () function for the graphicobject object, and then add the keyword dynamic before the function name

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.