Path: utzoo!utgpu!attcan!uunet!lll-winken!ames!mailrus!ukma!david From: david@ms.uky.edu (David Herron -- One of the vertebrae) Newsgroups: comp.lang.pascal Subject: Re: Enumerated types in TP40 Keywords: none Message-ID: <10838@s.ms.uky.edu> Date: 7 Jan 89 03:05:14 GMT References: <363@lafcol.UUCP> Reply-To: agollum@engr.uky.edu Distribution: na Organization: U of Kentucky, Mathematical Sciences Lines: 49 In article <363@lafcol.UUCP> pilgrimk@lafcol.UUCP (Guru Jee) writes: >How can the number of elements in an enumerated type be determined? > > e.g. type > Enum1 = (One, Two, Three, Four); > Enum2 = (_One, _Two, _Three); If you must do this at runtime, then something like var DummyArr = array[Enum1] of byte ... HowManyEnums = sizeof(DummyArr); ought to work. Another method which requires some attention if you change the declaration of Enum1 would be: const Enum1Max:Enum1 = Four; ... HowManyEnums = ord(Enum1Max) + 1; The best solution would be simply to define a constant with the value you want: const HowManyEnums = 4; TP 5.0 allows expressions to define constants so something like const Enum1Max:Enum1 = Four; HowManyEnums:byte = succ(ord(Enum1Max)); Would also work (though this solution and its runtime counterpart above depend on how TP implements enumerated types, and may break in the future). There may be an even better solution available under 5.0 (I don't have it, myself). Kenneth Herron -- <-- David Herron; an MMDF guy <-- ska: David le casse\*' {rutgers,uunet}!ukma!david, david@UKMA.BITNET <-- Now I know how Zonker felt when he graduated ... <-- Stop! Wait! I didn't mean to!