unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm1 = class(TForm)
    PassWord: TEdit;
    InputEdit: TEdit;
    Label2: TLabel;
    Label1: TLabel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;  EInValidation = class(Exception)
  public
    ErrorCode: integer;
    Constructor Create(Const Msg:string; ErrorNum: integer);
  end;  EInvalidPassWord = class(EInValidation)
  public
    Constructor Create;
  end;  EInvalidInput = class(EInValidation)
  public
    Constructor Create(Const ErrorNum: integer);
  end;var
  Form1: TForm1;implementation{$R *.dfm}{ EInValidation }constructor EInValidation.Create(const Msg: string; ErrorNum: integer);
begin
  inherited Create(Msg);
  ErrorCode:= ErrorNum;
end;{ EInvalidPassWord }constructor EInvalidPassWord.Create;
begin
  inherited Create('输入的密码不正确',0);
end;{ EInvalidInput }constructor EInvalidInput.Create(const ErrorNum: integer);
var
  Msg: string;
begin
  case ErrorNum of
     1: Msg:= '无法把字符串转成数字';
     2: Msg:= '输入的数字已经超过范围';
  else
     Msg:= '输出数据有问题';
  end;
  inherited Create(Msg,ErrorNum);
end;procedure TForm1.Button1Click(Sender: TObject);
Const
  CurrentPassWord = 'Delphi';
var
  Res: Real;
  Code: Integer;
begin
  try
    if PassWord.Text<>CurrentPassWord then
      raise EInvalidPassWord.Create;   //////***********
    Label2.Visible:= true;
    InputEdit.Visible:= true;
    InputEdit.SetFocus;
    PassWord.Visible:= false;
    Label1.Visible:= false;
  except
    on EInvalidPassWord do
    begin
      PassWord.Text:= '';
      raise;   ////////////////////////////////
    end;
  end;  try
    val(inputedit.Text,Res,Code);
    if code <> 0 then
      raise EInValidInput.Create(1);
    if (Res > 1) or (Res < 0) then
      raise EInvalidInput.Create(2);
    MessageDlg('Correct Input',mtInformation,[mbok],0);
  except
    on E:EInvalidInput do
    begin
      Inputedit.Text:='';                       ///////777777777
      MessageDlg(E.Message,mtWarning,[mbok],0); /////88888888888888
    end;
  end;
end;end.
当我输入错误的密码,则程序运行到//////***********这一行触发异常。
但运行到////////////////////////////////这一步后程序立刻进入/////88888888888888这一步,请问为何程序不执行///////777777777这一步?
则请问raise的工作机制是什么?他怎样运行?

解决方案 »

  1.   

    应该是优化掉了吧,因为你在后面没有调用到Inputedit.Text,
    用Inputedit.Clear;试试。作用应该是一样的,就是清空你的Inputedit里面的数据了。
      

  2.   

    有些调试的时候..比如..你用一个SHOWMESSAGE..用单步根本就没有用的..
    一下子就跳过去的了..只有在PROJECT当中的那个MESSAGE类型选项
    包含WINDOWS MESSAGE那个消息选项打勾的时候才会一步步来的..
    其它的..太长了..不想看..
      

  3.   

    只有在PROJECT当中的那个MESSAGE类型选项
    包含WINDOWS MESSAGE那个消息选项打勾
    我怎么找不到阿...
      

  4.   

    在debugger options里的那个是不是
    我怎么调试的时候就死掉了...ft