procedure Tdtmdl1.DataModuleCreate(Sender: TObject);
var
ini_FileName:string;
begin
ini_FileName:=ExtractFilePath(Application.ExeName)+'conn.ini';
if not FileExists(ini_FileName)then
begin
Application.MessageBox('数据库文件不存在','信息提示',MB_OK);
Application.Terminate;
end;
with con1 do
con1.ConnectionString:=Get_Db_Con_Str(ini_FileName);
con1.Connected:=False;
try
con1.Connected:=True;
except
Application.MessageBox('数据库连接失败请联系管理员','信息提示',mb_ok);
//在这里弹出窗口。
end;
end;
这是DataModule的配置检查。
7 个解决方案
#1
procedure Tdtmdl1.DataModuleCreate(Sender: TObject);
var
ini_FileName:string;
begin
ini_FileName:=ExtractFilePath(Application.ExeName)+'conn.ini';
if not FileExists(ini_FileName)then
begin
Application.MessageBox('数据库文件不存在','信息提示',MB_OK);
Application.Terminate;
end;
with con1 do
con1.ConnectionString:=Get_Db_Con_Str(ini_FileName);
con1.Connected:=False;
try
con1.Connected:=True;
except
Application.MessageBox('数据库连接失败请联系管理员','信息提示',mb_ok);
iniF:=TiniF.Create(Application);
iniF.Show;
//这里弹出配置窗体。但是登陆窗体也同时弹出了。不知道上面原因。
end;
end;
#2
以成功实现了。来个人接分吧
#3
实现的代码如下。还请指教下有上面其他方法
Application.Initialize;
Application.CreateForm(Tdtmdl1, dtmdl1);
if not Assigned(iniF) then
begin
if TLoginForm.ShowForm then
begin
Application.CreateForm(TIDCardRead_F, IDCardRead_F);
Application.CreateForm(TLeave, Leave);
Application.CreateForm(Tlavel, lavel);
end;
end;
Application.Run;
#4
Application.CreateForm(Tdtmdl1, dtmdl1);
if mrOk <> dtmdl1.isConnected then //通过自定义函数isConnected检查数据模块连接是否成功
begin
//不成功时, 打开配置窗口
with TInfo.create(Application) do
try
if mrOk <> showmodal then //取消配置则退出程序
Application.Terminate
finally
free;
end;
end;
procedure Tdtmdl1.DataModuleCreate(Sender: TObject);
var
ini_FileName:string;
begin
ini_FileName:=ExtractFilePath(Application.ExeName)+'conn.ini';
if not FileExists(ini_FileName)then
begin
Application.MessageBox('数据库文件不存在','信息提示',MB_OK);
Application.Terminate;
end;
with con1 do
con1.ConnectionString:=Get_Db_Con_Str(ini_FileName);
con1.Connected:=False;
try
con1.Connected:=True;
except
Application.MessageBox('数据库连接失败请联系管理员','信息提示',mb_ok);
iniF:=TiniF.Create(Application);
iniF.Show;
//这里弹出配置窗体。但是登陆窗体也同时弹出了。不知道上面原因。
end;
end;
#2
以成功实现了。来个人接分吧
#3
实现的代码如下。还请指教下有上面其他方法
Application.Initialize;
Application.CreateForm(Tdtmdl1, dtmdl1);
if not Assigned(iniF) then
begin
if TLoginForm.ShowForm then
begin
Application.CreateForm(TIDCardRead_F, IDCardRead_F);
Application.CreateForm(TLeave, Leave);
Application.CreateForm(Tlavel, lavel);
end;
end;
Application.Run;
#4
Application.CreateForm(Tdtmdl1, dtmdl1);
if mrOk <> dtmdl1.isConnected then //通过自定义函数isConnected检查数据模块连接是否成功
begin
//不成功时, 打开配置窗口
with TInfo.create(Application) do
try
if mrOk <> showmodal then //取消配置则退出程序
Application.Terminate
finally
free;
end;
end;
#5
#6
Application.CreateForm(Tdtmdl1, dtmdl1);
if mrOk <> dtmdl1.isConnected then //通过自定义函数isConnected检查数据模块连接是否成功
begin
//不成功时, 打开配置窗口
with TInfo.create(Application) do
try
if mrOk <> showmodal then //取消配置则退出程序
Application.Terminate
finally
free;
end;
end;
Application.CreateForm(Tdtmdl1, dtmdl1);
if mrOk <> dtmdl1.isConnected then //通过自定义函数isConnected检查数据模块连接是否成功
begin
//不成功时, 打开配置窗口
with TInfo.create(Application) do
try
if mrOk <> showmodal then //取消配置则退出程序
Application.Terminate
finally
free;
end;
end;