【delphi开源代码栏目提醒】:网学会员鉴于大家对delphi开源代码十分关注,论文会员在此为大家搜集整理了“DBSetup_Unit.pas”一文,供大家参考学习
unit DBSetup_Unit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TfrmDBSetup = class(TForm)
Label1: TLabel;
btnFilePath: TBitBtn;
btnOk: TBitBtn;
OpenPath: TOpenDialog;
edtDBFilePath: TEdit;
procedure btnFilePathClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure btnOkClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmDBSetup: TfrmDBSetup;
implementation
uses
Common_Unit, TeachMain_Unit, Login_Unit, DM_Unit;
{$R *.dfm}
procedure TfrmDBSetup.btnFilePathClick(Sender: TObject);
begin
if OpenPath.Execute then
edtDBFilePath.Text := OpenPath.FileName;
end;
procedure TfrmDBSetup.FormShow(Sender: TObject);
begin
edtDBFilePath.Text := DBConFileName(FileName);
end;
procedure TfrmDBSetup.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
//判断是否有主程序实例,如果没有关闭整个程序
if Assigned(frmLogin) then
//如果有,只关闭当前窗体
Close
else
Application.Terminate;
end;
procedure TfrmDBSetup.btnOkClick(Sender: TObject);
begin
if edtDBFilePath.Text = '' then
begin
Application.MessageBox('请选择数据库路径!','错误',16);
edtDBFilePath.SetFocus;
Exit;
end;
//打开数据库的连接
try
DM.ADOConn.Close;
DM.ADOConn.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;'
+ 'Data Source=' + edtDBFilePath.Text
+ ';Persist Security Info=False';
DM.ADOConn.Open;
except
Application.MessageBox('数据库连接失败!','错误',16);
Exit;
end;
//动态加载DLL,DLL中包含了读取INI文件的函数
try
DLLHandle := LoadLibrary('CommInfo.dll');
@WriteIni := GetProcAddress(DLLHandle,'WriteIni');
if @ReadIni <> nil then
WriteIni(FileName,'BDConn','DBConFileName',edtDBFilePath.Text);
Application.MessageBox('数据连接成功,请重新启动程序!','提示',64);
Application.Terminate;
finally
FreeLibrary(DLLHandle); //释放DLL
end;
end;
end.
上一篇:
dbSetup.pas
下一篇:
那些令你为之触动的好句子,感慨万分