Q&A

  • 예외처리를 하고 싶은데요...
edit3, edit4에 문자입력시 발행하는 에러에 대한 예외처리를 하고 싶은데요..

(try..except..end)문을 사용할려고 했는데..

도대체 어느곳에다가 코딩을 해야하는지 모르겠습니다...

예외처리가 잘 된다면...

밑에 부문의 공백입력시의 발생하는 이벤트 코딩도 필요없을꺼 같은데요..

누가 좀 도와 주세요..

좋은 하루 되세요..





procedure Tf_information.Button1Click(Sender: TObject);

begin



if edit1.text = '' then begin

showmessage('소모품명을 입력하세요');

edit1.SetFocus;

end

else if edit2.text = '' then begin

showmessage('단위를 입력하세요');

edit2.SetFocus;

end

else if edit3.text = '' then begin

showmessage('단가를 입력하세요');

edit3.SetFocus;

end

else if edit4.text = '' then begin

showmessage('현재고를 입력하세요');

edit4.SetFocus;

end

else if (RadioButton1.Checked = false) and

(RadioButton2.Checked = false) and

(RadioButton3.Checked = false) then

begin

showmessage('소모품을 구분하여 주세요');

end

else



With Query1 do begin

close;

SQL.Clear;

SQL.Add('select * from 새물품 where 품명= :a');

parambyname('a').asstring := edit1.Text;

open;

if not eof then

begin

MessageDlg('이미 등록하신 건입니다',mtinformation, [mbOK],0);

exit;

end;

SQL.Clear;

SQL.Add('insert into 새물품');

SQL.Add('values (:a, :b, :c, :d, :e)');

Parambyname('a').asstring := Edit1.Text;

Parambyname('b').asstring := Edit2.Text;

Parambyname('c').asfloat := strtofloat(Edit3.text);

if RadioButton1.Checked = true then begin

Parambyname('d').asfloat := 1.00;

Parambyname('e').asfloat := strtofloat(Edit4.text);

end

else if RadioButton2.Checked = true then begin

Parambyname('d').asfloat := 2.00;

Edit4.Text := '';

Edit4.Text := '0';

Parambyname('e').asfloat := strtofloat(Edit4.text);

end

else if RadioButton3.Checked = true then begin

Parambyname('d').asfloat := 3.00;

Edit4.Text := '';

Edit4.Text := '0';

Parambyname('e').asfloat := strtofloat(Edit4.text);



execsql;

end;

end;

initial_rtn;

close;

end;



1  COMMENTS
  • Profile
    잘난체 2001.10.12 18:42
    위의 코딩의 문제점은 예외처리의 문제가 아니라...

    입력사항이 입력이 되었나를 체크후에 이후로 진행하도록 코딩이 되어 있기

    때문에 문제 입니다...





    따라서 아래와 같이 바꾸시면

    if edit1.text = '' then begin

    showmessage('소모품명을 입력하세요');

    edit1.SetFocus;

    exit; < 이 부분을 추가>

    end



    예외처리는 DB에 저장시 하시면 됩니다..(DB에서 저장이 안될 수 있으니)

    insert시에 예외처리를 하시면 좋겠습니다...