Working on a console application using Delphi 7, and have run into a problem. I get an error on line 26 after
str := GetEnumName(TypeInfo (words[3].group),
The error reads “[Error] Project1.dpr(26): TYPEINFO standard function expects a type identifier” if anyone could help with this, it would be a great help!
Cheers!
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils,
TypInfo;
type
wordset = Record
word : String;
group : (flavour, colour, place, animal);
end;
Var
words : Array [1..50] of wordset;
str : string;
groups: string;
Begin
words[1].word := 'chocolate';
words[1].group := flavour;
words[2].word := 'vanilla';
words[2].group := flavour;
words[3].word := 'strawberry';
words[3].group := flavour;
str := GetEnumName(TypeInfo (words[3].group), integer(group));
readln;
end.
You are trying to pass there an enumeration field not a type identifier. You need to declare this enumeration separately (what is in the example below TGroup type).
Anyway there is an unwritten convention to use T prefix for each Type identifier so then you can easy recognize a Type. That’s the reason why I renamed Wordset to TWordset. Also word is not a good name for fields or variables because it’s also a data type in Delphi.