狼
狼牙
Unregistered / Unconfirmed
GUEST, unregistred user!
datamoudle在连接数据库异常后,如何退出主程序?
经查,倘若连接服务器地址不对的话,将弹出“连接数据库错误,请确定连接数据库正常!”
对话框,点击确定后,窗体消失,但在系统进程中,依然存在,因为其是datamoudle窗体,
没有继承form,所以无法用application.Terminate。请问,如何在出现该异常后,退出程序?
见所列出代码!
procedure TDM.DataModuleCreate(Sender: TObject);
var
MyIni:Tinifile;
i:integer;
begin
MyIni:= TIniFile.Create(Fmain.GetExePath+'config.ini');
try
ADOConnection1.ConnectionString:=MyIni.ReadString('Config','Cstr','error');
try
ADOConnection1.Connected:=true;
except
raise Exception.CreateFmt('%s 连接数据库错误,请确定连接数据库正常!',['错误!']);
exit;
end;
with Fmain do
begin
if ADOConnection1.Connected then
try
ADOTable1.Open;
ADOTable2.Open;
except
raise Exception.CreateFmt('%s 连接数据表打开错误!',['错误!']);
exit;
end;
end;
finally
MyIni.Free;
end;
end;
经查,倘若连接服务器地址不对的话,将弹出“连接数据库错误,请确定连接数据库正常!”
对话框,点击确定后,窗体消失,但在系统进程中,依然存在,因为其是datamoudle窗体,
没有继承form,所以无法用application.Terminate。请问,如何在出现该异常后,退出程序?
见所列出代码!
procedure TDM.DataModuleCreate(Sender: TObject);
var
MyIni:Tinifile;
i:integer;
begin
MyIni:= TIniFile.Create(Fmain.GetExePath+'config.ini');
try
ADOConnection1.ConnectionString:=MyIni.ReadString('Config','Cstr','error');
try
ADOConnection1.Connected:=true;
except
raise Exception.CreateFmt('%s 连接数据库错误,请确定连接数据库正常!',['错误!']);
exit;
end;
with Fmain do
begin
if ADOConnection1.Connected then
try
ADOTable1.Open;
ADOTable2.Open;
except
raise Exception.CreateFmt('%s 连接数据表打开错误!',['错误!']);
exit;
end;
end;
finally
MyIni.Free;
end;
end;