Arrays 帕斯卡字符串&;记录

Arrays 帕斯卡字符串&;记录,arrays,string,record,pascal,Arrays,String,Record,Pascal,这是我到目前为止的代码,以防你说不出我在写一本字典,可能每个字母都有一个东西,可能只有15个左右的随机条目。这是我到目前为止所拥有的 program Dictionary; uses crt; Type Asdf = String[26]; Definition = Record First, Full, NorV, Class : Asdf; End; Var A, B, C, D, E, F, g, h

这是我到目前为止的代码,以防你说不出我在写一本字典,可能每个字母都有一个东西,可能只有15个左右的随机条目。这是我到目前为止所拥有的

program Dictionary;

uses crt;

Type
 Asdf = String[26];
 Definition = Record
                    First, Full, NorV, Class : Asdf;
                    End;
Var
 A, B, C, D, E, F, g, h, i, j, k, l, m, n, o, p, q, r,
 s, t, u, v, w, x, y, z : Definition;

BEGIN
 a.First := 'a';
 a.Full := 'apple';
 a.NorV := 'noun';
 a.Class := 'fruit';

 b.First := 'b';
 b.full := 'bee';
 b.NorV := 'noun';
 b.Class := 'insect';

 c.first := 'c';
 c.full := 'cat';
 c.NorV := 'noun';
 c.class := 'animal';

 d.first := 'd';
 d.full := 'dunk';
 d.Norv := 'verb';
 d.class := 'action';

 e.first := 'e';
 e.full := 'egg';
 e.norv := 'noun';
 e.class := 'food';

 f.first := 'f';
 f.full := 'forget';
 f.norv := 'verb';
 f.class := 'action';

 g.First := 'g';
 g.Full := 'grape';
 g.NorV := 'noun';
 g.Class := 'fruit';

 h.First := 'h';
 h.Full := 'horse';
 h.NorV := 'noun';
 h.class := 'animal';

 i.First := 'i';
 i.Full := 'invent';
 i.NorV := 'verb';
 i.class := 'action';

 j.First := 'j';
 j.Full := 'jump';
 j.NorV := 'noun';
j.class := 'action';

 k.First := 'k';
 k.Full := 'kangaroo';
 k.NorV := 'noun';
 k.class := 'animal';

 l.First := 'l';
 l.Full := 'look';
 l.NorV := 'verb';
 l.class := 'action';

 m.First := 'm';
 m.Full := 'mango';
 m.NorV := 'noun';
 m.Class := 'fruit';

 n.First := 'n';
 n.Full := 'noose';
 n.NorV := 'noun';
 n.class := 'object';

 o.First := 'o';
 o.Full := 'orangutan';
 o.NorV := 'noun';
 o.class := 'animal';

 p.First := 'p';
 p.Full := 'prod';
 p.NorV := 'verb';
 p.class := 'action';

 q.First := 'q';
 q.Full := 'queen';
 q.NorV := 'noun';
 q.class := 'royalty';

 r.First := 'r';
 r.Full := 'run';
 r.NorV := 'verb';
 r.class := 'action';

 s.First := 's';
 s.Full := 'shoot';
 s.NorV := 'verb';
 s.class := 'action';

 t.First := 't';
 t.Full := 'train';
 t.NorV := 'noun';
 t.class := 'transport';

 u.First := 'u';
 u.Full := 'umbrella';
 u.NorV := 'noun';
 u.class := 'object';

 v.First := 'v';
 v.Full := 'vegetable';
 v.NorV := 'noun';
 v.class := 'vegetable';

 w.First := 'w';
 w.Full := 'walk';
 w.NorV := 'verb';
 w.class := 'action';

 x.First := 'x';
 x.Full := 'xylophone';
 x.NorV := 'noun';
 x.class := 'object';

 y.First := 'y';
 y.Full := 'yank';
 y.NorV := 'verb';
 y.class := 'action';

 z.First := 'z';
 z.Full := 'zoo';
 z.NorV := 'noun';
 z.class := 'area';

 Writeln ('Type the first letter of the word you want to view');
 Readln (
结束


我应该在末尾放些什么,以便在键入时可以进行搜索?如果有必要,我可以添加更多变量。救命啊

尝试将字符设置在字符串的位置1。第一个有效的原因是编译器可以将“a”字符串类型转换为字符。其他字符串不能进行类型转换。放下索引,事情就会正常(未经测试)


正如您所发现的,很难枚举多个变量

标准的解决方案是将它们放在一个阵列中

var 
  myarray: array['A'..'Z'] of Definition;
然后列举

var
  myloopvar: Char;

for myloopvar := 'A' to 'Z' do
  if myarray[myloopvar].firstletter = 'X' then
    DoSomething;
var
  myloopvar: Char;

for myloopvar := 'A' to 'Z' do
  if myarray[myloopvar].firstletter = 'X' then
    DoSomething;