📄 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.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -