A Conditional Object Example

Description

This topic refers to the AlphaSports sample database provided with Alpha Anywhere.

Overview 

A conditional object is a multi-level rectangular frame used to conditionally display and hide groups of objects. Conditional objects behave like tabbed subforms, except that instead of tabs, the object has multiple layers, which appear and disappear based on the expressions you enter. A layer appears when its expression evaluates to TRUE. If no expression evaluates to true, the default layer appears.

images/UM_Conditional_Object.gif

The COND1 layers that become visible or invisible depending on the value of the variable vcLayoutType, which you can set by clicking the selected button or radio button.

Procedure: Creating the Form's Variables 

The COND1 conditional object assumes that the developer has created the necessary form variables:

  1. In the Form Editor toolbar click the 'V' icon.

  2. Create the vcReports, vcLetters, and vcLabels variables as Level "Layout" and type "Character".

  3. Enter the variables' initial values of "Customer List", "Letter to Customers", and "Customer Labels". These values match entries in Listbox1, Listbox2, and Listbox3 and provide valid default selections.

  4. Create the vcLayoutType variables as Level "Session" and type "Character".

  5. Enter the default value of "Reports" for vcLayoutType. This value matches a value in the Dropdown1 list box and provides a valid default selection.

  6. Click the OK button to return to the Form Editor.

    images/UG_Variables_Definition.gif

Procedure: Creating the Controlling Radio Buttons 

  1. Select the Radio Button tool and sketch a box large enough to contain 3 radio buttons.

  2. In the Field Select dialog select "Var" from the Table list and "vcLayoutType" from the Available Fields list, then click OK.

  3. Right click the radio button control and select Properties....

  4. Display the Choices tab.

  5. In the Choices for control list select "User Defined".

  6. Enter "Labels", "Letters", and "Reports" into the large text box, then click OK.

Procedure: Creating the Controlling Buttons 

  1. Select the Button tool and sketch a button on the form.

  2. Set the button label to "Labels".

  3. Click Next >.

  4. Enter the following code and click Finish.

    vcLayoutType = "Labels"
    topparent:cond1.refresh()
  5. Create a second button, setting the label to "Letters", copying the above code, but setting vcLayoutType equal to "Letters".

  6. Create a third button, setting the label to "Reports", copying the above code, but setting vcLayoutType equal to "Reports".

Procedure: Creating the COND1 Conditional Object 

The following procedure assumes that the developer has opened the form in the Form Editor. Follow these instructions to create a conditional object similar to COND1 :

  1. Select the conditional object tool on the Toolbar.

  2. Sketch the object's dimensions on the form.

  3. Right click on the object and select Properties....

  4. Enter the expression Var->vcLayoutType = "Reports" into the Condition Expression field.

  5. Enter "Reports" into the Label field.

  6. Click "".

  7. Enter the expression Var->vcLayoutType = "Labels" into the Condition Expression field.

  8. Enter "Labels" into the Label field.

  9. Click "".

  10. Enter the expression Var->vcLayoutType = "Letters" into the Condition Expression field.

  11. Enter "Letters" into the Label field.

  12. Click the OK button to return to the Form Editor.

  13. Right click the conditional object to display the following menu.

    images/AL_form_custqueryreport_cond1_labels.gif
  14. Place a list box on the conditional object.

  15. On the Setup tab of the Field Properties dialog box, select "VAR->vcReports" in the Field list.

    images/AL_form_custqueryreport_listbox1_setup.gif
  16. Click the Choices tab.

  17. Select "Computed Automatically" from the Choices for control are list.

  18. Select "Report Layouts" in the Source list.

  19. Click the OK button to return to the Form Editor.

    images/AL_form_custqueryreport_listbox1_choices.gif
  20. Right click the conditional object.

  21. Select "Letters" to display the Letters layer.

  22. Place a list box on the page.

  23. On the Setup tab of the Field Properties dialog box, select "VAR->vcLetters" in the Field list.

  24. Click the Choices tab.

  25. Select "Computed Automatically" from the Choices for control are list.

  26. Select "Letter Layouts" in the Source list.

  27. Click the OK button to return to the Form Editor.

  28. Right click the conditional object.

  29. Select "Labels" to display the Labels layer.

  30. Place a list box on the page.

  31. On the Setup tab of the Field Properties dialog box, select "VAR->vcLabels" in the Field list.

  32. Click the Choices tab.

  33. Select "Computed Automatically" from the Choices for control are list.

  34. Select "Label Layouts" in the Source list.

  35. Click the OK button to return to the Form Editor.

  36. Click the various radio buttons to display different layers of the conditional object.