Welcome!

PowerBuilder Authors: Chris Pollach, Yeshim Deniz, Jayaram Krishnaswamy, Kevin Benedict, Avi Rosenthal

Related Topics: PowerBuilder

PowerBuilder: Article

Sherlock II Loggin In

Sherlock II Loggin In

My first column on Sherlock appeared in the August issue of PBDJ (Vol. 7, issue 8). In that article we set up our development environment. Now we need to log in. Before we do that let's review just a bit.

We have a window with only a DataWindow control. The DataWindow is external; Table 1 shows its columns.

This DataWindow is free-form and basically used to gather information about the login process (see Table 1). I've added some graphics that can be downloaded from the source code on the PBDJ Web site.

In the last article we discussed how to automatically execute events by parsing out the tag property for any column the user clicks on. Listings 1 and 2 repeat the string parsing routine I used (and continue to use almost daily in my own work). These are inside a nonvisual object (class) that I call dojo_n_cst_string. One is case sensitive and the other isn't. They're both called of_getTokenizedValue. Since they have the same name, they're polymorphic. The last argument is optional.

I failed to show you two other functions in that object that determine if the object passed in as an argument is 'good' (not null and valid). Again, we have a polymorphic function here. In one case we're determining if the object is null and the other if it's valid. The distinguishing characteristic is whether the argument is a PowerObject or a type ANY. The two functions are in Listings 3 and 4, both named of_good.

Now that we're set up, let's start adding functionality to the DataWindow. Note that along the top there's a checkbox for Save To Registry. Let's start with that. If the user checked that last time, then we need to restore that value. Clearly the next thing to do is check the registry to see if the user did check Save To Registry. If the user did, then we'll have something in the registry giving us some default values.

We need a key under which to save our registry entry. If you aren't familiar with registry functions, look up registryGet in your help file. Let's call that key HKEY_CURRENT_USER\Software\Sher- lock. Next we add some code to the open event of the window. That code (see Listing 5) looks for our database information in the registry. Those values that are found (if any) are used in setItems for the DataWindow control.

We're automatically populating the DataWindow in the open event if the user saved his or her values in the registry. If the user didn't, then we're not.

The next thing to do is make sure the user can, if he or she wishes, save to the registry. This would happen if the user checked the Save To Registry when he or she tried to log in. We finally get to use our tag attribute. Go to your DataWindow painter and add the following tag to your button:

[post] ue_login

With our functionality this will automatically call the ue_login event (if we defined it) whenever that button is clicked. Open your ancestor DataWindow and put the code from Listing 6 in the Clicked event. Now go back to your w_main, edit the clicked event of your DataWindow control, and take out the call to close the parent.

Create a user-defined event called ue_login and insert the code from Listing 7.

Let's see, where are we? We now have a window that can be used to log in. Can we enhance this window? Of course we can. We could add the ability to save to an ini file. That would require more code in the open event of the window and the ue_login event of the DataWindow. You could also add a button that allows you to cancel the application. As it stands right now, you can't get out unless you connect to the database. That's not acceptable. I assume you're quite capable of handling these things on your own if you want Ð after all, this column is about DataWindows, not generic application development.

In the next article we'll move on to the meat of this series, the dynamic report generation. It'll require a new window. Until then, you can download the code and try it out on your own.

More Stories By Rik Brooks

Richard (Rik) Brooks is the owner of Brooks & Young, a Sybase Code
Partner. He's been using PowerBuilder since 1990 and has worked as an
independent consultant for major corporations in the U.S. for the last five years. He has authored several books on PowerBuilder including PFC Programmer's Reference Manual and The Definitive
DataWindow.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.