델파이
폼의 OnCloseQuery와 Application.HnadleException(self)사용
미스터몽키
2009. 10. 29. 23:09
폼이 close되기 전에 폼을 닫을지 말지를 결정하는 CanClose변수를 통해 결정 true면 닫히고, false면 복귀된다.
Application.HandleException(self)는 에러발생메세지 창을 통해 에러를 알린다.
procedure TForm1.Form1CloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if Employees.Active then
try
{ When closing, update the database if connected or save it to disk if not }
if Connection.Connected then
UpdateData else
SaveData;
except
on E: Exception do
begin
Application.HandleException(Self); //에러내용과 함께 에러창이 디스플레이
CanClose := MessageDlg('Data not saved/updated, exit anyway?', //그래도 종료할지 말지 결정
mtConfirmation, mbYesNoCancel, 0) = mrYes;
end;
end;
end;