Microsoft KB Archive/191872

= PRB: Enum HelpStrings Not Displayed in Properties Window =

Article ID: 191872

Article Last Modified on 7/16/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Enterprise Edition

-



This article was previously published under Q191872



SYMPTOMS
HelpStrings of Enum types in an ActiveX control developed in Visual C++ are not displayed in the Properties Window of Visual Basic 5.0 and 6.0. This behavior differs from previous versions of Visual Basic.



CAUSE
When an ActiveX control is developed in Visual C++, Enum types can be declared in the control's ODL file, and subsequently used by the control's properties. HelpStrings can also be associated with the members of the Enum to help define the property.

Here is a segment of an ODL file for an ActiveX control built in MFC: typedef enum tagLineStyleConstants {      [helpstring("Solid")]        lsSolid      = 0, [helpstring("Dash")]        lsDash       = 1, [helpstring("Dot")]         lsDot        = 2, [helpstring("Dash-Dot")]    lsDashDot    = 3, [helpstring("Dash-Dot-Dot")] lsDashDotDot = 4, } LineStyleConstants; ....    properties: // NOTE - ClassWizard will maintain property information here. //   Use extreme caution when editing this section. //AFX_ODL_PROP When the ActiveX control has been sited on a form in Visual Basic 4.0, you can see that the value of the LineStyle property, when viewed from the Properties Window, is composed of all the HelpStrings of the Enum type. It looks similar to the following:

0 - Solid

1 - Dash

2 - Dot

3 - Dash-Dot

4 - Dash-Dot-Dot

However, when this ActiveX control is sited on a form in Visual Basic 5.0 or 6.0, you can see that the value of the LineStyle property is composed of all the members of the Enum type rather than the HelpStrings. It looks similar to the following:

0 - lsSolid

1 - lsDash

2 - lsDot

3 - lsDashDot

4 - lsDashDotDot

Visual Basic 5.0 or 6.0 reserve the HelpStrings for descriptive explanations of each Enum member when viewed in the Object Browser.



RESOLUTION
There are several solutions for this issue:

 Make the name of each element in your Enum types as meaningful as possible so users of your control could figure out its meaning from the name. Implement the members of the IPerPropertyBrowsing interface, which allow clients to query your control for descriptive strings for properties viewed from a Property Page and Visual Basic's Properties Window. Create property pages for your properties. The Enum HelpStrings will be used in property pages.

For additional information regarding solution 2 or 3 above, please refer to the following article in the Microsoft Knowledge Base:

141488 SAMPLE: Using Enumerated Properties in an OLE Control





STATUS
This behavior is by design.



Steps to Build an ActiveX Control in MFC
 Start Visual C++ 5.0 and create a new control project using the MFC ActiveX ControlWizard. Name the project EnumTest, and click OK. When the wizard comes up, press Finish to accept the default settings.</li> From the ClassView tab, right-click on _DEnumTest and select "Add Property" from the context menu. Add the name LineStyle to the dialog's External Name text box, and choose long as the data type. Accept the default variable name and function by click OK.</li>  From the Files tab, open the EnumTest.odl file and add the following inside your type library, just under the importlib(STDTYPE_TLB) statement: typedef enum tagLineStyleConstants {        [helpstring("Solid")]        lsSolid      = 0, [helpstring("Dash")]        lsDash       = 1, [helpstring("Dot")]         lsDot        = 2, [helpstring("Dash-Dot")]    lsDashDot    = 3, [helpstring("Dash-Dot-Dot")] lsDashDotDot = 4, } LineStyleConstants; </li>  Continue down and change the data type for the newly-added property from a long to the enum type LineStyleConstants: // NOTE - ClassWizard will maintain property information here. // Use extreme caution when editing this section. //AFX_ODL_PROP </li> Compile your control. MFC will register the control for you.</li></ol>

Steps to Test the Control in Visual Basic

 * 1) Open Visual Basic and create a new Standard EXE project. Form1 is created by default.
 * 2) From the Project|Components menu, add the control EnumTest.ocx to the Visual Basic Toolbox.
 * 3) Add an instance of the EnumTest.ocx control to Form1.
 * 4) From the Properties window, look for the LineStyle property. You can change the value of the LineStyle property from the dropdown combobox. On Visual Basic 4.0, these items will be composed of the Enum type HelpStrings. On Visual Basic 5.0 and Visual Basic 6.0, the member names themselves will appear.

Additional query words: kbDSupport kbDSD kbVBp kbVBp400 kbVBp500 kbVBp600 kbCtrlCreate kbVC500 kbWizard

Keywords: kbprb KB191872

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.