它提示错误是
Build
[Error] Unit1.pas(39): Operator not applicable to this operand type
[Error] Unit1.pas(41): Operator not applicable to this operand type
[Error] Unit1.pas(43): Operator not applicable to this operand type
[Error] Unit1.pas(45): Operator not applicable to this operand type
[Error] Unit1.pas(47): ':=' expected but '=' found
[Error] Unit1.pas(47): Operator not applicable to this operand type
[Error] Unit1.pas(50): Declaration expected but 'IF' found
[Error] Unit1.pas(53): Illegal character in input file: ';' ($A3BB)
[Error] Unit1.pas(54): '.' expected but ';' found
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
字符串应该可以通过数组的方式对单个字符进行索引的,为什么不能进行判断呢????
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
edt1: TEdit;
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
var
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
var
char1 : set of Char;
Str:string;
i:Integer;
begin
char1:=[];
Str:=edt1.Text;
for i:=0 to Length(Str)-1 do
begin
if Str[i] = 'a' or Str[i] = 'A' then
char1:=char1+['a']
else if Str[i]='e' or Str[i]='E' then
char1:=char1+['e']
else if Str[i]='i' or Str[i]='I' then
char1:=char1+['e']
else if Str[i]='o' or Str[i]='O' then
char1:=char1+['e']
else Str[i]='u' or Str[i]='U' then
char1:=char1+['e'];
end;
if char1 <> [] then
ShowMessage('含有元音字母')
else
ShowMessage('不含有元音字母');
end;
end.
|