Now you add a one-line script to open the login window as soon as the application starts executing. Although you could change the script in the Application object Open event to open the login window, in this tutorial you make the call to open the login window from the Open event of the MDI frame window. This window (w_pbtutor_frame) was created by the Template Application wizard.
In wizard-generated script, the frame window is called by the Application object Open event. When you add a call to open the login window from the MDI frame window Open event, the login window still displays before the frame window. Because the login window is a response window, it temporarily blocks execution of the remainder of the frame window Open event script.
In this exercise you:
Now you modify the frame window Open event script to open the login window.
Wizard-generated script The frame window Open event already has a script associated with it that was generated by the Template Application wizard. The script creates an instance of a wizard-generated user object that serves as a sheet (window) manager. The Open script then calls the ue_postopen event.
The ue_postopen event registers sheet windows with the sheet manager. The event is posted to the end of the messaging queue for the window and is not processed until the remainder of the Open script (that you add in this lesson) is executed.
Select File>Open from the menu bar.
Make or verify the following selections in the Open dialog box:
Open dialog box item |
Selection to make (or verify) |
---|---|
Target |
pbtutor—currently your only target |
Libraries |
pbtutor.pbl—currently your only library; if you cannot see the full library name, you can drag the edge of the dialog box to increase its size |
Object Name |
w_pbtutor_frame |
Objects of Type |
Windows—you must make sure this is selected before you can select a named object of this type |
Using |
Painter |
The w_pbtutor_frame object is the main application window created by the Template Application wizard.
Click OK.
The Window painter opens and displays views of the main application window in the painter workspace.
If the Script view is not open, you can open it by selecting View>Script in the workspace menu bar or by double-clicking inside the Layout view.
Move the cursor to the top of the Script view.
The view title bar rolls down. It contains a pushpin button on the left and a maximize/minimize button and a close button on the right.
Click the pushpin in the title bar of the Script view.
The title bar of the Script view reads:
Script - open for w_pbtutor_frame returns long
Make sure the Open event displays in the Script view.
The PowerScript code in the Script view is preceded by comments.
Using comments A comment in PowerScript is indicated by either two forward slashes (//) at the start of a single-line comment, or a slash and an asterisk (/*) at the start and an asterisk and a slash (*/) at the end of a single-line or multiline comment. Comments are not parsed by the script compiler.
You now modify the Open event script to cause the login window to display.
Click after the parentheses in the line that reads:
this.Post Event ue_postopen ( )
The ue_postopen event does not take any arguments.
Press Enter twice.
This adds a blank line in the Script view for legibility. The cursor moves to a new line following the blank line.
Type Open the login window
on
the new line in the Script view.
Click the Comment button in PainterBar2.
Two slashes appear in front of the line you typed—it is changed into a comment.
Move the cursor to the end of the comment.
Press Enter to add a new line.
Type open (w_welcome)
on
the new line.
This calls the Open function to display the login window you created.
Now you compile the script you just typed. In this exercise, you use a pop-up menu item to compile the script. PowerBuilder also compiles a script when you close the Script view or when you select a different object, event, or function for display in the Script view.
Handling errors in scripts When there is an error in a script, an error window displays at the bottom of the Script view with the line number of the error and the error message.
To find an error Click on an error message to move the cursor to the line that contains that error. After you correct the error, you can try to compile the script again.
Commenting out errors PowerBuilder does not save scripts that have errors. If you want to save a script that has errors, select the entire script and click the Comment button to comment out the code. You can come back later, uncomment the code, and fix the problem.
Right-click anywhere in the Script view script area.
Select Compile from the pop-up menu.
The script compiles. You do not leave the Script view or the Window painter workspace.
Select File>Save from the menu bar.
Select File>Close from the menu bar.
The Window painter closes.