views:

896

answers:

1

Hi,

I have created a custom TAction type which has 2 additional properties which are of type string, and enumeration.

The string value is showing in the object inspector fine, however, the enumeration type is not appearing at all. How can I get a custom enumeration type to display as a drop down property value in the object inspector?

+10  A: 

Enum properties should use the default TEnumProperty class to edit the properties.

It looks like the RTTI information can not be found. Where is the enum type defined? In the same file as the component?

And do you use an enum type with custom values like:

TMyEnum = (aA = 1, aB = 3);

Explanation: if you define an enum with values, you create a subrange type with predefined constants. So the above is to be interpreted as:

type
  TMyEnum = 1..3;
const
  aA : TMyEnum = 1;
  aB : TMyEnum = 3;

This can lead to strange situations like: Succ(aA) is not aB but 2. The information is in the help (Language Guide) Simple types [Enumerated Types with Explicitly Assigned Ordinality].

This can be the source of the problem.

If all else fails, you can create your own property editor. Which is able to change the enum property in the object inspector. Normally you will be able to use the default TEnumProperty. But if that is not enough, you can roll your own:

Step 1, derive a property editor. In your case probably TEnumProperty (unit DesignEditors) will be enough probably with little changes.

Step 2, be sure the GetValue and SetValue methods work fine. They need to translate a string into the enum property and back.

Step 3, if you want real special editing be sure the override the edit method.

Step 4, be sure th eeditor attributes are valid.

Step 5, register the property editor using RegisterPropertyEditor.

Just look at the component writers guide for more information.

Gamecat
Hi,Thanks for your advice. I was defining the enum with custom values, so I removed these and just let the compiler generate the values and it worked fine.However, just for future reference, do you know why you can't assign custom values to an enum property in the default object inspector?
James
If you assign custom values, it isn't an enum any more (its somewhere in the help file).
Gamecat
Added a full explanation.
Gamecat