Hi, I understand that you can create a cls with the definition of an enum. In my case I want to test with a Enum for the different states an item can have. In the database we already save those values but they are saved as integers (0 means "new", 1 means "replaced", ...) So now I want to use Enums for those values so that thee are better readable in the coding. I thought that those enums could be used like: if item.Status eq ItemStatus:New then .... or assign item.Status = ItemStatus:New But it looks like you can't use Enums that way. Am I correct here or is there some way that I can use them this way?. The explanation is that you can only assign an Enum to a field/variable that has that Enum-type. So I should define a variable of the type ItemStatus, assign that the value of item.Status and then check if that variable eq itemStatus:New Or I can also use the getvalue-/toString-methods to assign the value (like item.status = ItemStatus:new:getvalue()) But again, I find it strange that I just can not use <enum>:<value> (like itemStatus:New) in a comparison or assignment. Can't the language convert this internally depending on the data-type where it's compared/assigned with? (so without the need of defining a variable of that enums-type or by using the GetValue- or GetString-method) Regards
You need to use either the :GetValue() :ToString() methods or INTEGER()/INT64()/STRING() functions.
assign item.Status = ItemStatus:New:GetValue().
assign item.Status = integer(ItemStatus:New).
There is an idea asking that the cast should be automatic when there is a db field on the other side of the equation. You can vote for it here.
Simon L Prinsloo
Damn, thats what I feared