0

Possible Duplicate:
Why do I get “type has no typeinfo” error with an enum type

I have a component with a property like this:-

enum class Foo {VAL0, VAL1, VAL2, VAL4 =4};

class TDummy : public TComponent
{
...
  Foo f;
  TDummy() : f(Foo:VAL2) {};

__published: 
  __property Foo foo{ read = f, write = f};
}

However, when installed, the IDE object instpector doesn't give me a dropdown list of choices for 'foo', but just displays an edit field with the value '2' in it.

How can I get the IDE to show "VAL2" instead of "2", and display a dropdown list of choices VAL0/VAL1/VAL2, etc../?

Community
  • 1
  • 1
Roddy
  • 66,617
  • 42
  • 165
  • 277

1 Answers1

1

This is because the enum values aren't contiguous. Change the enum declaration from

enum class Foo {VAL0, VAL1, VAL2, VAL4 =4};

...to...

enum class Foo {VAL0, VAL1, VAL2, VAL3, VAL4};

And the property will work correctly in the object inspector. Of course, VAL3 can now be chosen, which isn't ideal.

Delphi doesn't support non-contiguous enums, so there's no way the RTTI can represent a non-contiguous set of values.

Roddy
  • 66,617
  • 42
  • 165
  • 277