unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
    TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    Edit2: TEdit;
    Button2: TButton;
  private
    { Private declarations }
  public
    { Public declarations }    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    end;
    EResultTooBig=class(Exception)
      Num:Integer;
      constructor Create(N:Integer);
   end;
   EResultTooSmall=class(Exception)
       Num:Integer;
   end;
  constructor EResultTooBig.Create(N:Integer);
   begin
     Num:=N;
   end;
   
 var
  Form1: TForm1;
  ResultNum:Integer;
  //Num:Integer;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);begin   ResultNum:=strtoint(Edit1.Text);   //if (ResultNum<100)and(ResultNum>0) then
      //ShowMessage('输入的数据符合要求');
   try
      if ResultNum>=100 then
         raise EResultTooBig.Create(ResultNum)
      else if ResultNum<=-1 then
         raise EResultTooSmall.CreateFmt('数据不可小于0。',[]);
      except
         on EResultTooBig do Writeln('Wrong: 返回值不可大于100。');
         on EResultTooSmall do Writeln('Wrong:返回值不可小于0。');
      else
         Writeln('Wrong:其他运行时错误。');
         if  ResultNum>=100 then
              ShowMessage('输入的数据大于100');
                if ResultNum<=-1 then
                  Edit2.Text:=Format('%-10d',[ResultNum]);      end;
      //Readln;
   procedure TForm1.Button2Click(Sender: TObject);
begin
   close;
end;end.   小可初学Delphi,就遇见了这个问题,这个程序的错误提示如下:[Error] Unit1.pas(32): Identifier redeclared: 'EResultTooBig.Create'
[Error] Unit1.pas(33): Undeclared identifier: 'Num'
[Error] Unit1.pas(70): Statement expected but 'PROCEDURE' found
[Error] Unit1.pas(26): Unsatisfied forward or external declaration: 'EResultTooBig.Create'
[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
      TForm1 = class(TForm)
        Label1: TLabel;
        Edit1: TEdit;
        Label2: TLabel;
        Edit2: TEdit;
        Button1: TButton;
        Button2: TButton;
        private
        {Private  declarations  }
        public
        {Public  declarations  }    procedure  Button1Click(Sender:  TObject);
        procedure  Button2Click(Sender:  TObject);
      end;  EResultTooBig = class(Exception)
        Num:Integer;
        constructor  Create(N:Integer);
      end;  EResultTooSmall = class(Exception)
        Num:Integer;
      end;var
     Form1:  TForm1;
     ResultNum:Integer;
     //Num:Integer;implementation{$R *.dfm}constructor EResultTooBig.Create(N:Integer);
    begin
      Num:=N;
    end;procedure TForm1.Button1Click(Sender:  TObject);
    begin
      ResultNum:=strtoint(Edit1.Text);
      //if  (ResultNum <100)and(ResultNum> 0) then ShowMessage('ÊäÈëµÄÊý¾Ý·ûºÏÒªÇó');
      try
        if ResultNum >= 100 then
          raise EResultTooBig.Create(ResultNum)
        else
          if ResultNum <= -1 then raise EResultTooSmall.CreateFmt('Êý¾Ý²»¿ÉСÓÚ0¡£',[]);
      except
        on EResultTooBig do Writeln('Wrong:  ·µ»ØÖµ²»¿É´óÓÚ100¡£');
        on EResultTooSmall do Writeln('Wrong:·µ»ØÖµ²»¿ÉСÓÚ0¡£');
      else
        Writeln('Wrong:ÆäËûÔËÐÐʱ´íÎó¡£');
        if  ResultNum >= 100  then ShowMessage('ÊäÈëµÄÊý¾Ý´óÓÚ100');
        if  ResultNum <=-1  then Edit2.Text:=Format('%-10d',[ResultNum]);
      end;
      //Readln;
    end;procedure  TForm1.Button2Click(Sender:  TObject);
    begin
      close;
    end; end. 
      

  2.   

    楼上的已经帮你修改了LZ的错误就是把应该在实现部分的代码写到interface部分了,以后注意就是
      

  3.   

    我把程序修改如下:
        
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
        TForm1 = class(TForm)
        Label1: TLabel;
        Edit1: TEdit;
        Button1: TButton;
        Edit2: TEdit;
        Button2: TButton;
        Label2: TLabel;
      private
        { Private declarations }
      public
        { Public declarations }    procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        end;    EResultTooBig=class(Exception)
          Num:Integer;
          constructor Create(N:Integer);
       end;
       
       EResultTooSmall=class(Exception)
           Num:Integer;
       end;
     var
      Form1: TForm1;
      ResultNum:Integer;
     // Num:Integer;implementation{$R *.dfm}constructor EResultTooBig.Create(N:Integer);
       begin
         Num:=N;
       end;procedure TForm1.Button1Click(Sender: TObject);begin   ResultNum:=strtoint(Edit1.Text);   //if (ResultNum<100)and(ResultNum>0) then
          //ShowMessage('输入的数据符合要求');
         // Edit2.Text:=Format('%-10d',[ResultNum]);
       try
          if ResultNum>=100 then
             raise EResultTooBig.Create(ResultNum)
          else if ResultNum<=-1 then
             raise EResultTooSmall.CreateFmt('数据不可小于0。',[]);
          except
             on EResultTooBig do showMessage('Wrong: 返回值不可大于100。');
             on EResultTooSmall do showMessage('Wrong:返回值不可小于0。');
          else
             showMessage('Wrong:其他运行时错误。');
             //if  ResultNum>=100 then
                  //ShowMessage('输入的数据大于100');
                   // if ResultNum<=-1 then
                      //Edit2.Text:=Format('%-10d',[ResultNum]);      end;
          //Readln;
       end;procedure TForm1.Button2Click(Sender: TObject);
    begin
       close;
    end;end.
     
        可是当我电击运行的时候出现一个对话框,其内容如下:        
         Debugger Exception Notification(对话框标题)
      Project Project1.exe raised exception class EReader with message 'Invalid property value'.Proces
     stopped.Use Step or Run to continue.
       希望再给小弟指点一下,谢谢!