Conditional Objects
by Steve Workings
Originally published in Alpha Forum
Posted at www.workings.com January 20, 2001

Alpha Software did a great job by creating tabbed objects in Alpha Five version 3. Tabbed objects showed Alpha’s technical prowess, helped keep Alpha Five in the market, and provided a really cool tool. But for all that, I seldom use tabbed objects. The reasons?

1. Tabbed objects often consume Windows resources at an astonishing pace in the development phase;

2. Tabbed objects often have a "jumpy" or unstable feel to them at runtime; and

3. I’ve found something better.

What’s better? Conditional objects. In ninety percent of the cases that a tabbed object is appropriate, so is a conditional object. Paired with a multi-state button, a conditional object works just fine, doesn’t eat Windows resources during development, and offers a rock-solid feel to the finished product.

For my example I’ll use a form that I designed for a car-leasing company. Figure 1 shows the form in design mode. There are four main parts to this form:


Figure 1 - A5 form in design mode. The handles show the conditional object.

1. The conditional object, which consumes most of the form, is the active object in Figure 1 as evidenced by its handles.

2. A few fields along the top of the form display all the time, regardless of which "page" of the conditional object is showing.

3. A set of buttons at the top right help the user find information in a variety of ways.

4. A multi-state button at the bottom left works hand-in-hand with the conditional object to help the user select different views.

Figure 2 shows the same form in view mode looking at the Vehicle Info page of the conditional object. Figure 3 is produced by clicking the "Payments" option of the multistate button.


Figure 2 - The same form in view mode, with the "Vehicle Information" object showing.


Figure 3 - The same form in view mode, with the "Payments" object showing.

Let’s look at the construction of both the conditional object and the multistate button to see how these two work together and produce these results.

In design mode, right click on a conditional object and select properties to display a dialog like that shown in Figure 4. You can see that this example has five different specified conditions. Each condition is simply the value of a session-level variable called "Show." The first condition is


Figure 4 - Defining the conditional object

var->show = "Car"

The second condition is

var->show = "Cust"

and so on.

What this means is that, depending on the value of the Show variable, the conditional object will display a different page.

After you specify the various conditions you want to use, you can go back to the form, right click on the conditional object again and get a list of all the different pages of the object that are available. Select any one of these pages (or conditions) to place your fields or other objects and controls.

OK, so we’ve specified that the conditional object will display a different page based upon the value of a variable called Show. But how to change the value of Show? The answer lies in the use of the multistate button.

When you first create a multistate button, Alpha Five prompts you to associate it with a field. In this case, the association is with the Show variable. After dropping the button on the form, right click on it and select properties, then go to the Choices tab of the properties box. Figure 5 shows these properties for this example. For each label that you create, another "state" is added to the multistate button. And since the field that this multistate button controls is the Show variable, the values specified in the right-hand column match the conditions of the conditional object exactly.


Figure 5 - Defining the multistate button to set the variable.

Click on the Vehicle Info part of the multistate button and the Show variable equals "Car." Click on the Customer Info part of the button and Show will equal "Cust." This is a very simple way to quickly change the value of a variable.

There’s only one more small piece remaining to make this work; simply changing the value of the Show variable isn’t enough -- you also need to resynch the screen -- or more precisely the conditional object -- to the new value. The simplest way to do this is to right click on the multistate button, edit its Actions, and select the OnChange event. All you need is a single simple line of Xbasic here:

parentform.resynch()

That’s it! After you’ve dropped a few fields on the various pages of the conditional object and saved the form, try running it and just click among the multistate button’s choices. Smooth, steady and reliable!

This example makes use of a conditional object that fills most of the form. I’ve even developed an entire -- though rather simple -- application for a customer by filling the form completely with one conditional object that held three conditions. You can create you own genies with form-sized conditional objects or use them in smaller sizes in a variety of ways. And while I haven’t taken the time to do it, you could also set up several buttons along the edge of a conditional object and -- with the right Xbasic -- have the basic look of a tabbed object!

Once you try and compare the smooth solid feel of conditional objects against tabbed objects, I’ll bet you’ll use a whole lot more conditional objects.

###