When it comes to dynamic invocation types, let's look at the reference methods for objects, properties, functions, and events:
The development process of the PowerBuilder 6.0 application is actually the definition and use process of various objects. All objects have names, and are distinguished by names. In PowerScript, the method of accessing an object's properties, functions, and events is simple, using a dot as a marker, specifically, the format of accessing an object property is:
Object name. Object Properties
For example, a statement that sends user input from a single-line edit box sle_name to a string variable userenter can be written as:
Userenter=sle_name. Text
Where Sle_name is the name of a Single-line edit box object, text is the Text property of a single-line edit box.
The functions and events that access the object in the program are formatted as:
{objectname.} {type} {CallType} {when} functionname ({argumentlist})
Among them, the elements enclosed in braces can be omitted according to the circumstances, and the meaning of each component is:
ObjectName is the object name;
The type value is a function or an event that indicates the Access function or the events, and the default value is a function;
CallType is used to indicate the timing of the PowerBuilder lookup function, valid values are:
STATIC (default): Compile-time lookup function, if not present, generate compilation error
DYNAMIC: The program runtime lookup function, if it does not exist, generates a run-time error
When is used to indicate whether a function or event is executed immediately or after execution of the current program segment is performed, values are:
TRIGGER (default): Immediate execution
Post: Execution after the current program segment has finished executing
FunctionName indicates the function or event name called
ArgumentList gives a parameter to a function or event
For example, to move the input focus to the sle_name of a single-line edit box, write the statement in the program: Sle_name. SetFocus () can be. To immediately execute the button Cb_name Click event handler, write the statement: Cb_name. EVENT TRIGGER clicked () can be.
As seen above, dynamic is a dynamically called function or event that, when you specify a dynamic call, functions and events do not necessarily exist at compile time. You tell the compiler: Trust me, there must be a proper function or event at runtime here. For dynamic invocations, PowerBuilder waits until execution to find a function or event. This gives you greater programming flexibility.
Please compare the following sample (excerpt):
The Undo feature is available in most popular applications today, and the undo () function can be used in PowerBuilder to implement this feature. The Undo () function can be used for DataWindow, Editmask, Multilineedit, Richtextedit, and Singlelineedit objects, if the undo operation is performed on only one object. Simply type 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 perform the undo () operation on when we write the script, how can we solve the problem? In PowerBuilder, functions such as Undo () are available only to visual objects, and all visual objects inherit from the System object class Graphicobject. Therefore, we can define a Graphicobject object's instance variable go_object, wait until the runtime to use the GetFocus () function to determine the specific Operation object. Then use the typeof () function to determine the type of the current object, and then use the Choose Case statement to refer to the different instance variables according to the different types, the code reads 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 undo!")
End Choose
In fact, we can use the dynamic Call function method to solve this problem simply, that is, call the Undo () function on the Graphicobject object, and then add the keyword dynamic before the function name.