procedure TForm1.Button1Click(Sender: TObject);
type
  Tvowels=set of Char;
var
  Vowels:Tvowels;
  Vowels:=['a','e','i','o','u'];
  if Edit1.text[1] in Vowels then
    Label1.caption:='OK';
  else
    Label1.caption:='不OK';
end;
运行后报错如下:
  [Error] Unit1.pas(33): Identifier redeclared: 'Vowels'
  [Error] Unit1.pas(33): Identifier expected but string constant found
  [Error] Unit1.pas(34): ',' or ':' expected but '.' found
  [Error] Unit1.pas(34): Constant expression expected
  [Error] Unit1.pas(35): ',' or ':' expected but '.' found
  [Error] Unit1.pas(37): Identifier redeclared: 'Label1'
  [Error] Unit1.pas(37): ',' or ':' expected but ':=' found
  [Error] Unit1.pas(39): Type expected but 'END' found
  [Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      Tvowels=set of Char;                           <-定义要在这
      TForm1 = class(TForm)
        Button1: TButton;
        Edit1: TEdit;
        Label1: TLabel;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      Vowels:Tvowels;
    begin
      Vowels:=['a','e','i','o','u'];
      if Edit1.text[1] in Vowels then
        Label1.caption:='OK'               <-else前不应该加分号
      else
        Label1.caption:='不OK';
    end;end.
      

  2.   

    procedure TForm1.Button2Click(Sender: TObject);
    type
      Tvowels=set of Char;
    var
      Vowels:Tvowels;
    begin
      Vowels:=['a','e','i','o','u'];
      if Edit1.text[1] in Vowels then
        Label1.caption:='OK'
      else
        Label1.caption:='不OK';
    end;
      

  3.   

    我也正想再问问呢。照楼上的确实可以行,但是在produce中进行类型定义应该也可以的啊。我碰到的例程序只是begin和end没加上去而已。