前几天在csdn上看到的,然后我用的! 主要是:PromptDataSource在adodb单元中 function TdmGlob.GetConnectionString:String; var Reg:TRegistry; begin //获得数据库连接串 Reg:=TRegIniFile.Create; try Reg.RootKey:=HKey_Current_User; Reg.OpenKey('\SoftWare\海南ATM网络监控',True); g_sBackGround:=Reg.ReadString('Background'); Result:=Reg.ReadString('ConnectString'); if Result='' then begin Result:=PromptDataSource(Application.Handle,''); if Result<>'' then Reg.WriteString('ConnectString',Result); end; finally Reg.Free; end; end;
主要是:PromptDataSource在adodb单元中
function TdmGlob.GetConnectionString:String;
var
Reg:TRegistry;
begin
//获得数据库连接串
Reg:=TRegIniFile.Create;
try
Reg.RootKey:=HKey_Current_User;
Reg.OpenKey('\SoftWare\海南ATM网络监控',True);
g_sBackGround:=Reg.ReadString('Background');
Result:=Reg.ReadString('ConnectString');
if Result='' then
begin
Result:=PromptDataSource(Application.Handle,'');
if Result<>'' then
Reg.WriteString('ConnectString',Result);
end;
finally
Reg.Free;
end;
end;
uses AdoConEd
调用方法:
procedure TForm1.Button1Click(Sender: TObject);
begin
EditConnectionString(ADOConnection1) ;
end;