function TDm.OpenConn():Boolean;//连接数据库 begin try if ADOConnection1.Connected then ADOConnection1.Close; ADOConnection1.ConnectionString := LoadIni() ; ADOConnection1.Connected := True; Result := True; except begin Result := False; end; end; end; if Cdm.dm.OpenConn then begin end else begin ShowMessage('无法连接数据库服务器,请重新配置系统!'); fmSysSetup:= TfmSysSetup.Create(Application); fmSysSetup.Showmodal; fmSysSetup.Free; end; end;
在未连接上数据库时可以自动弹出数据库连接对话框。 implementation uses adoconed; {$R *.DFM}procedure TForm1.FormCreate(Sender: TObject); begin if EditConnectionString(adoconnection1) then showmessage(adoconnection1.connectionstring);end;
if connection1.connected then ShowMessage('已连接!');
begin
try
if ADOConnection1.Connected then ADOConnection1.Close;
ADOConnection1.ConnectionString := LoadIni() ;
ADOConnection1.Connected := True;
Result := True;
except
begin
Result := False;
end;
end;
end;
if Cdm.dm.OpenConn then
begin
end
else
begin
ShowMessage('无法连接数据库服务器,请重新配置系统!');
fmSysSetup:= TfmSysSetup.Create(Application);
fmSysSetup.Showmodal;
fmSysSetup.Free;
end;
end;
implementation
uses adoconed;
{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
begin
if EditConnectionString(adoconnection1) then
showmessage(adoconnection1.connectionstring);end;
ShowMessage('已连接!');