在Delphi中调用"数据链接属性"对话框设置ConnectionString

项目需要使用"数据链接属性"对话框来设置ConnectionString,查阅了一些资料,解决办法如下:

1.Delphi

Delphi中比较简单,步骤如下:

方法1: use ADOConED;
    ADOConED.EditConnectionString(ADOConnection1);
    这样我们就可以使用:
    ShowMessage(ADOConnection1.ConnectionString)
    查看ADOConnection1ConnectionString


方法2: ADOConnection1.ConnectionString:=PromptDataSource(handle,'');
 或者:
    ADOConnection1.ConnectionString:=PromptDataSource(handle,ADOConnection1.ConnectionString);

 

:PromptDataSource函数的代码:
function PromptDataSource(ParentHandle: THandle; InitialString: WideString): WideString;
var
DataInit: IDataInitialize;
DBPrompt: IDBPromptInitialize;
DataSource: IUnknown;
InitStr: PWideChar;
begin
Result := InitialString;
DataInit := CreateComObject(CLSID_DataLinks) as IDataInitialize;
if InitialString <> '' then
DataInit.GetDataSource(nil, CLSCTX_INPROC_SERVER,
PWideChar(InitialString), IUnknown, DataSource);
DBPrompt := CreateComObject(CLSID_DataLinks) as IDBPromptInitialize;
if Succeeded(DBPrompt.PromptDataSource(nil, ParentHandle,
DBPROMPTOPTIONS_PROPERTYSHEET, 0, nil, nil, IUnknown, DataSource)) then
begin
InitStr := nil;
DataInit.GetInitializationString(DataSource, True, InitStr);
Result := InitStr;
end;
end;

posted on 2017-08-28 19:41  癫狂编程  阅读(670)  评论(0编辑  收藏  举报

导航

好的代码像粥一样,都是用时间熬出来的