try
strtoInt(Edit5.text); 
strtofloat(Edit6.text); exceptshowmessage('产品数量和出厂价必须是数字!'); 
//---------------------------------能在这里强行中止程序运行吗? 
end; 

解决方案 »

  1.   

    即便是Application.Terminate; 了,还是好象运行了后面的语句?why
      

  2.   

    try
    strtoInt(Edit5.text); 
    strtofloat(Edit6.text); exceptshowmessage('产品数量和出厂价必须是数字!'); 
    Application.Terminate; 
    end; 
      

  3.   

    我的意思是如果不是数字就showmessage('产品数量和出厂价必须是数字!');
    不要在运行下面的程序。
      

  4.   

    procedure TForm3.BitBtn8Click(Sender: TObject);
    //var
    //num1:integer;
    //num2:double;
    begintry
    strtoInt(Edit5.text);
    strtofloat(Edit6.text);
    except
    //Finally
    showmessage('产品数量和出厂价必须是数字!');
    Application.Terminate; 
    end;//num1:=strtoint(Edit5.text);
    //num2:=strtoFloat(Edit6.text);//if not (isInt(num1) or isFloat(num2)) then
      //      showmessage('产品数量和出厂价必须是数字!');
    //end;  with ADOTable1 do begin 
     if State<>dsInsert then
            Insert;//还会出错吗?
    ADOTable1.FieldByName('productNo').asstring:=Edit1.text;
    ADOTable1.FieldByName('productNo').asstring:=Edit1.text;
    ADOTable1.FieldByName('productName').asstring:=Edit2.text;
    ADOTable1.FieldByName('productSpec').asstring:=Edit3.text;
    ADOTable1.FieldByName('productInType').asstring:=Edit4.text;ADOTable1.FieldByName('productNum').asInteger:=strtoint(Edit5.text);
    ADOTable1.FieldByName('productToFactoryPrice').asFloat:=strtoint(Edit6.text);
    ADOTable1.FieldByName('units').asstring:=Edit7.text;
            Post;
            ADOTable1.Refresh;
            MessageDlg('记录添加成功!',mtwarning,[mbOK],0) ;
    end; //ADOTable1.Insert;增加一空白记录
    //将Edit_name部件的Text属性复制给数据库的name字段;//ADOTable1.Post;提交end;
      

  5.   

    你用
    try
     ....
    finally 
     ....
    end;
    试试
      

  6.   

    ??
    应该把插入记录的语句放在try...和except之间吧?
      

  7.   

    在except中ShowMessage句后加一句abort;这就禁止了本次事件中后续语句的运行。