procedure TForm1.Button1Click(Sender: TObject);vars,r:string;begincase s of 'K' : r:='A';'L' : r:='B';'M' : r:='C';'N' : r:='D';'O' : r:='E';'P' : r:='F';'Q' : r:='G';'R' : r:='H';'S' : r:='I'elser:='X';end;end;明明正确的语句,为什么编译时出现如下错误:[Error] main.pas(116): Ordinal type required;(该句指向case s of)
[Error] main.pas(117): Incompatible types: 'Integer' and 'Char'
[Error] main.pas(118): Incompatible types: 'Integer' and 'Char'
……
[Error] main.pas(117): Incompatible types: 'Integer' and 'Char'
[Error] main.pas(118): Incompatible types: 'Integer' and 'Char'
……
改成char
procedure TForm1.Button1Click(Sender: TObject);vars,r:char;begincase s of 'K' : r:='A';'L' : r:='B';'M' : r:='C';'N' : r:='D';'O' : r:='E';'P' : r:='F';'Q' : r:='G';'R' : r:='H';'S' : r:='I'elser:='X';end;end;
procedure TForm1.Button1Click(Sender: TObject);vars,r:string;begincase s[1] of 'K' : r:='A';'L' : r:='B';'M' : r:='C';'N' : r:='D';'O' : r:='E';'P' : r:='F';'Q' : r:='G';'R' : r:='H';'S' : r:='I'elser:='X';end;end;
s:=Edit1.Text;
case s[1] of 'K': r := 'A'; 'L': r := 'B'; 'M': r := 'C'; 'N': r := 'D'; 'O': r := 'E'; 'P': r := 'F'; 'Q': r := 'G'; 'R': r := 'H'; 'S': r := 'I' else r := 'X'; end;
ShowMessage(r);
end;
case integer