Defining a Choice

A choice has a fixed set of properties that define the kind of choice it is, its content, and its availability. You can also associate additional information with the choice. This help topic discusses the following subjects:

Distinguishing One Choice from Others

The primary value used to distinguish one choice from another is its Type property. The type can be any string unique enough to be distinguished from other types introduced by other choices. You might find it useful to determine a naming convention for the types you specify to prevent type conflicts. You could use a string based on a GUID, although it would make writing and understanding code more difficult.

Specifying a Choice's Content

A Choice also has content associated with it. This content can be stored in a Description property or a Text property. Both are strings; however, they are distinguished by their typical uses. The Description property is a user-friendly string that expands the meaning of the Text property. Typically, you use the Description property to populate user interface elements like text boxes or combo boxes and you use the Text property to generate code.

For example, the Text property might contain a URL such as HTTP://MySite.com and the Description property might have "My Web Site." Or if the Choice object shares information about available data connections, the text might be an SQL statement and the description might be "Sales by Product."

Sharing More Than Type and Text

Your DTC may need to share more information than the fixed properties. You can associate tags with a choice to extend the information offered. Tags are named, VARIANT-valued properties and can be used to associate arbitrary data with the choice, including references to other objects. For more information about how tags can be used, see "Identifying a Choice of Interest" in Subscribing to Choices.

Setting Choice Properties Through a User Interface

You can use a callback object to set the Text property of a choice. Typically the callback object displays a dialog box prompting the user for the text. For example, you can use a New File choice that displays a Save As dialog box.

You can also use message boxes to collect values for use in choices. Using the ProcessPopUpChoice method, you can display a dialog box or similar interface to allow the user to fill in the text of the choice. For example, in a DTC created in Visual Basic, a message box could use the Choice's properties to fill in a default based on the current value in the combo box. When the user has finished, ProcessPopUpChoice should return the text of the user's selection in the s parameter. If the user cancels the dialog box, ProcessPopUpChoice should set the cancel parameter to True.

Note   If you want to use filters with PopUp choices, use the Description property because the Text property never matches the PopUp text.

When you ask for the Text property of the choice, the object is called using the ProcessPopUpChoice method. You can specify ProcessPopUpChoice to do anything you need, as long as it returns a string value that can be used for the Text property. Typically, the object displays a message to prompt the user for a string.