[fpc-pascal] What is wrong with this enum and array related code
Vincent Snijders
vincent.snijders at gmail.com
Sun Sep 12 14:01:28 CEST 2010
2010/9/12 Frank Church <vfclists at gmail.com>:
> program testnums;
> //{$APPTYPE CONSOLE}
>
> uses
> Classes, SysUtils;
> type
> stType = (stLite := -100, stDb, stBothLite, stBothDb); //settings
> location Type
> stTypes = Array [stType] of integer;
> var
> d : stType;
> s : string;
> i : integer;
> begin
> writeln('');
> for i := Ord(low(stType)) to Ord(high(stType)) do
> begin
> d := stTypes[i - Ord(low(stType))];
> writestr(s,d);
> writeln(d + ' ' + IntToStr(Integer(i)));
> end;
> readln;
>
> end.
I think the array and enum are correct, but the usage isn't. I did not
compile this code, but I expect a type mismatch error. You are using
an integer as index in d := stTypes[i - Ord(low(stType))], but you
declared stTypes an array to be indexed by stType.
More information about the fpc-pascal
mailing list