Enum init value (OE 11.6)

Posted by doa on 24-Nov-2015 06:10

Why isn't it possible to define a variable as enum with an init value?

For example:


DEFINE VARIABLE oTest AS Enum.TestEnum NO-UNDO INIT Enum.TestEnum:Test.

Posted by Laura Stern on 24-Nov-2015 08:54

Actually, there really is no such thing as a reference type in the ABL other than perhaps BY-REFERENCE temp-tables.  I suppose you could think of an object reference or handle that way.  But really the reference or handle is just passed by value when used a parameter.

Anyway, so much for philosophy.  I think it is very valid question.  But I believe the answer is that in order to do the initialization that way the AVM would have to create an instance of the enum during the DEFINE statement.  The AVM does not support doing that at the moment.  Though I have to say that with Enums it would be easier in that there really is no possibility of an error as you might have with another class.  No code is actually run, like you would have with a constructor of any other class type.  But as it is conceivable that we may allow more code in enums in the future, this would be a dangerous thing to rely on.

All Replies

Posted by bronco on 24-Nov-2015 06:13

probably because an Enum is a reference type and not a value type.

Posted by Laura Stern on 24-Nov-2015 08:54

Actually, there really is no such thing as a reference type in the ABL other than perhaps BY-REFERENCE temp-tables.  I suppose you could think of an object reference or handle that way.  But really the reference or handle is just passed by value when used a parameter.

Anyway, so much for philosophy.  I think it is very valid question.  But I believe the answer is that in order to do the initialization that way the AVM would have to create an instance of the enum during the DEFINE statement.  The AVM does not support doing that at the moment.  Though I have to say that with Enums it would be easier in that there really is no possibility of an error as you might have with another class.  No code is actually run, like you would have with a constructor of any other class type.  But as it is conceivable that we may allow more code in enums in the future, this would be a dangerous thing to rely on.

This thread is closed