Introduction to PowerBuilder

HomePrevious Lesson: Connecting to the Database
Next Lesson: Linking DataWindow to the Database

Allowing the User to Cancel the Login

Sometimes, may be by mistake, user executes the application. Then he would like to come out of the application instead of proceeding with the login. We make a provision for this by writing the following code for the clicked event of the cb_cancel CommandButton. If the user clicks on this button or press the Esc key, we simply stop the execution of the application:
// Object: cb_cancel in window w_login
// Event: clicked
Halt

A connection error can be simulated by not typing in a password or changing one of the values. When a connection error occurs, you'll get a message box telling you what the error is and asks if you want to try again.

If the users are on a Novell network, the user information can be got automatically by using the Novell Network Bindery Service function call nwDSWhoAmI(), or by using the Windows SDK call GetEnvironmentVar(). These would enable you to distribute a single .INI file for all users, calling the relevant function rather than reading the hard coded userid from the .INI file.

To use these functions, you need to purchase additional Novell Network Bindery Service DLLs from Powersoft. Register the DLLs with your application by declaring them as local or global external functions. You can then call them like any other user-defined function in your script. We'll look at how to use Windows SDK calls in a later session, where we cover how to declare external functions.

If the full path for the .INI file is not specified, PowerBuilder first looks in the directory from where PowerBuilder was started and then looks in the working directory specified while creating the relevant program items. This is true only when you are running the application under the development environment, i.e., from within PowerBuilder.

When you create a .EXE file and run it independently, PowerBuilder first looks in the working directory specified for the .EXE file program item. If the file isn't found in that directory, it then searches in the directories appearing in the AUTOEXEC.BAT path.

Instead of clicking on the cb_cancel CommandButton, if the user press the Esc button, we want to do the same thing, i.e., close the application. How is it done? To tell you the truth, there is nothing that needs to be done. Why? Because, you already took care of it by turning on the cb_cancel's 'Cancel' property, when you painted the w_login window in the window painter exercises. What does it mean? When the user presses the Esc button, PowerBuilder automatically fires the clicked event of the button that has its 'Cancel' property turned on.

If there aren't any connection errors, we close the login window and open the w_product_master window. Append the following line of code to the Open event of the application object.
// Object: Application Object
// Event: Open
Open (w_product_master)

Actually, when PowerBuilder encounters an Open() function, it opens the specified window and doesn't wait for the results of that command and continues with the next command. That means, it should open w_login and w_product_master simultaneously and the user should see both the windows at the same time. In practice, w_product_master is not seen until w_login window is closed. Why? This is because, w_login window is a window of type Response. That means, PowerBuilder doesn't execute the next line of code, until the response window is closed.
HomePrevious Lesson: Connecting to the Database
Next Lesson: Linking DataWindow to the Database