Enumerations represent a set of symbolic values. In IDL, an enumeration defines a set of constants that are represented by symbolic names, for example:
enum ShirtSize { xl, l, m, s }
The ActiveX proxy maps this IDL enumeration to an Microsoft IDL (MIDL) enumeration as:
typedef enum { xl = 0, 1 = 1, m = 2, s = 3 } ShirtSize;
You can declare IDL enumerations globally, within a module, or within an interface. The ActiveX proxy supports only enumerations that are declared in a module or interface. Enumerations map to MIDL enumerations as follows:
The IDL enumeration e declared in module m translates to MIDL enumeration e in type library m.
Enumeration e declared in interface i in module m translates to MIDL enumeration i_e in type library m. MIDL does not allow enumerations to be declared inside an interface, so the interface is declared at the type-library level, and the interface and enumerations names are concatenated to avoid name collisions between like-named IDL enumerations declared in different interfaces.
In Visual Basic, you can refer to an enumeration’s members as:
enum.member
Where enum is the enumeration name and member is the member name.
If your ActiveX development tool supports MIDL enumerations, you should use the symbolic member names rather than the hard coded constants. Doing so isolates your code from changes to the IDL enumeration definition.
In tools that do not support enumerations, you must use the enumeration’s integer constants rather than the symbolic names. However, the constants associated with an enumeration are subject to change if the IDL definition changes. To minimize the effect of changes to your source code, declare variables and assign the constant value to them. For example:
dim shirtsize_xl as integer
shirtsize_l = 0
Copyright © 2005. Sybase Inc. All rights reserved. |