Aquablue Posted June 11, 2014 Share Posted June 11, 2014 Hello all, I'm using quite a lot of enumerated variables for a script in progress, since this kind of variable allows usage of the case statement which is very readable. I noticed that SCAR supports usage of the Ord() function, which returns the ordinal of an enumerated variable. So for example, when I have the following: type TestType = (Left, Up, Right, Down); var Test : TestType; begin Test := Right; WriteLn('The ordinal of Test is '+IntToStr(Ord(Test))); end. This would print "The ordinal of Test is 2". In Delphi, you also have the GetEnumName() function, which as I understand works the other way around, it would return the name of the ordinal of an enumerated variable. So setting Test := 2 in the above example and calling WriteLn('The name of Test is '+GetEnumName(Test)); should print "The name of Test is Right". Does SCAR support a function similar to GetEnumName()? Quote Link to comment Share on other sites More sharing options...
FHannes Posted June 11, 2014 Share Posted June 11, 2014 There's no such similar function available, but I can check if I might be able to add one. I'm currently focusing my efforts on the development of SCAR 4, which features a far more powerful engine, but I do intend to release SCAR 3.41 soon as a small maintenance update to 3.40 with some bugfixes and minor additions. Whether or not it is possible will depend on the engine itself, but I'm quite confident that internally it simply represents enumerations as ordinal values. So I will have to see if I can figure out a way to extract runtime type information, which might not be possible. I'll let you know whether or not I'm able to do this. Quote Link to comment Share on other sites More sharing options...
Aquablue Posted June 11, 2014 Author Share Posted June 11, 2014 That sounds very nice! A GetEnumName() function isn't crucial for me, but it would be nice to have. I'll be sure to read up on SCAR 4! Quote Link to comment Share on other sites More sharing options...
FHannes Posted June 11, 2014 Share Posted June 11, 2014 Well, I have evaluated the possibility of implementing this, and short of majorly overhauling the engine, there's no way to do it. The type information is not kept, not even in the compiler. Rather than building the enum types, the compiler simply converts the enum values into ordinal constants with a temporary link back to the type in the compiler for range validation. The small amount of type information that the compiler does keep is pretty much entirely removed before reaching runtime. I tried to implement a function to grab the enum names from the compiler during runtime by modifying the compiler to keep additional type info, but the compiler destroys everything but the program itself right after compilation, changing that would also be quite messy. Quote Link to comment Share on other sites More sharing options...
Aquablue Posted June 15, 2014 Author Share Posted June 15, 2014 Sorry to hear that, but thanks for the trouble! Quote Link to comment Share on other sites More sharing options...