[fpc-pascal] Re: What is wrong with this enum and array related code

Frank Church vfclists at gmail.com
Sun Sep 12 16:48:20 CEST 2010


On 12 September 2010 13:05, Vincent Snijders <vincent.snijders at gmail.com>wr=
ote:

> 2010/9/12 Frank Church <vfclists at gmail.com>:
> > I need to elaborate more on this code
> >
> > On this line
> >
> > d :=3D stTypes[i - Ord(low(stType))];
> >
> > since stTypes is an array, I expect stTypes[n], with n being 1 to 4,  to
> > retrieve an array value and as 'i - Ord(low(stType)) evaluates to integ=
er
> it
> > should compile but it generates an error.
> >
> > What would be the correct way?
> >
> > On 12 September 2010 12:51, Frank Church <vfclists at gmail.com> wrote:
> >>
> >> program testnums;
> >> //{$APPTYPE CONSOLE}
> >>
> >> uses
> >>   Classes, SysUtils;
> >> type
> >>    stType =3D (stLite :=3D -100, stDb, stBothLite, stBothDb); //settin=
gs
> >> location Type
> >>    stTypes =3D Array [stType] of integer;
> >> var
> >>  d : stType;
> >>  s : string;
> >>  i : integer;
>
> >> begin
> >>  writeln('');
> >>  for i :=3D Ord(low(stType)) to Ord(high(stType)) do
> for  d:=3D low(stType) to high(stType) do
>
> >>  begin
> >>   d :=3D stTypes[i - Ord(low(stType))];
> i :=3D stTypes[d];
> >>    writestr(s,d);
> >>    writeln(d + ' ' + IntToStr(Integer(i)));
> >>  end;
> >>  readln;
> >>
> >> end.
> >>
> >> --
> >> Frank Church
> >>
> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> >> http://devblog.brahmancreations.com
> >
> >
> >
>

Does that mean that although an enum is an ordinal type, an integer cannot
be coerced into using it to index an array?



> > --
> > Frank Church
> >
> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> > http://devblog.brahmancreations.com
> >
> > _______________________________________________
> > fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> > http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> >
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>



-- =

Frank Church

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
http://devblog.brahmancreations.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freepascal.org/lists/fpc-pascal/attachments/20100912/a095=
d72a/attachment.htm


More information about the fpc-pascal mailing list