enums - Any simplier way to 'read' enumerated types in pascal? -


user inputs integer corresponds value of defined enumerated type. need assign value variable t. thought of:

type test = (red,green,blue,fish); var t:test;     n,i:integer; begin   readln(n);   t:=red;   i:=1 n     t:=succ(t); end. 

am overcomplicating task? possible write simpler alogrithm?

you should able cast integer enumerated type, example:

t := test(n); 

if want go other way, use ord:

n := ord(t); 

that should let move numerically item in list. can check bounds with:

ord(low(test))) 

and

ord(high(test)) 

..where test type.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -