Can you define an ENUM with some keywords included? - Forum - OpenEdge Development - Progress Community

Can you define an ENUM with some keywords included?

 Forum

Can you define an ENUM with some keywords included?

This question is answered

I'm trying to create an ENUM with No and Yes as part of the list, but it is not letting me. Can you at least do a named member with specific string value? 

Verified Answer
  • The inability to use No and Yes appears to be a defect, as the documentation states:

    The rules for member names follow the same rules that are in place for variable and property names. Member names are case insensitive and can be reserved keywords.


    It fails in both OE11.7.4 and OE12.0, so you should report it as a defect.

    Simon L Prinsloo

    www.vidisolve.com

All Replies
  • Sounds like a bug!?

  • It's probably more an intended limitation. You cannot use all ABL keywords as identifiers anywhere. This might be due to syntax ambiguity or just complexity in the compiler implementation.

    "Can you at least do a named member with specific string value?"

    No, the string value is always the Enum member name. You need to live with that. Enums are not made to provide anything "human readable". Emums are there to produce a type with a defined set of values. Enums are to make API's and Interfaces more clear and generally help to avoid programming mistakes.

    What we typically to, is to use the enum type name and member name as keys to retrieve a human readable value from our translation service. That way we maintain a localizable version of the human readable representation.

    Architect of the SmartComponent Library and WinKit

    Consultingwerk Ltd.

  • This is a limitation. The constants yes/no/true/false are not allowed as member names in classes or enums.

  • If you really really want a string enum, you can use the type-safe-enum pattern and create some static class exposing things quite similar to a standard oe enum from a syntax perspective.

  • If you really really want a string enum, you can use the type-safe-enum pattern and create some static class exposing things quite similar to a standard oe enum from a syntax perspective.

  • The inability to use No and Yes appears to be a defect, as the documentation states:

    The rules for member names follow the same rules that are in place for variable and property names. Member names are case insensitive and can be reserved keywords.


    It fails in both OE11.7.4 and OE12.0, so you should report it as a defect.

    Simon L Prinsloo

    www.vidisolve.com