本文介绍了Delphi ODBC连接对话框组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在考虑向应用程序添加ODBC数据库连接。
用户将在运行时配置和选择他们的数据库odbc连接。
有任何组件我需要的系列对话吗?
允许用户选择数据源类型,选择驱动程序,已经浏览
定义的ODBC连接等。
Cheers
Sam
解决方案
如果使用ADO组件,您可以试试这个。
选项1
使用
OleDB,
ComObj,
ActiveX;
function Edit_ADO_ODBC_ConnectionString(ParentHandle:THandle; InitialString:WideString; out NewString:string):Boolean;
var
DataInit:IDataInitialize;
DBPrompt:IDBPromptInitialize;
DataSource:IUnknown;
InitStr:PWideChar;
begin
结果:= False;
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;
{
DBPROMPTOPTIONS_WIZARDSHEET = $ 1;
DBPROMPTOPTIONS_PROPERTYSHEET = $ 2;
DBPROMPTOPTIONS_BROWSEONLY = $ 8;
DBPROMPTOPTIONS_DISABLE_PROVIDER_SELECTION = $ 10;
}
如果成功(DBPrompt.PromptDataSource(nil,ParentHandle,DBPROMPTOPTIONS_PROPERTYSHEET,0,nil,nil,IUnknown,DataSource))then
begin
InitStr:= nil;
DataInit.GetInitializationString(DataSource,True,InitStr);
NewString:= InitStr;
结果:= True;
end;
end;
结果:= Edit_ADO_ODBC_ConnectionString(0,OldConnectionString,NewString);
选项2
使用
ADODB;
PromptDataSource(Self.Handle,InitialString);
选项3
使用
ADODB,
AdoConEd;
procedure TMainForm.Button2Click(Sender:TObject);
Var
ADOConnection1:TADOConnection;
begin
ADOConnection1:= TADOConnection.Create(Self);
EditConnectionString(ADOConnection1);
end;
您必须选择Microsoft OLE DB提供程序ODBC驱动程序 p>
再见。
I am thinking about adding ODBC database connectivity to an application.
The user will at runtime configure and select their database odbc connection.
Are there any components that will give me the required series of dialogs ?
Allowing the user to select the data source type, select drivers, browse alreadydefined ODBC connections etc.
CheersSam
解决方案
You can try this, if you are using ADO components.
Option 1
Uses
OleDB,
ComObj,
ActiveX;
function Edit_ADO_ODBC_ConnectionString(ParentHandle: THandle; InitialString: WideString;out NewString: string): Boolean;
var
DataInit : IDataInitialize;
DBPrompt : IDBPromptInitialize;
DataSource: IUnknown;
InitStr : PWideChar;
begin
Result := False;
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;
{
DBPROMPTOPTIONS_WIZARDSHEET = $1;
DBPROMPTOPTIONS_PROPERTYSHEET = $2;
DBPROMPTOPTIONS_BROWSEONLY = $8;
DBPROMPTOPTIONS_DISABLE_PROVIDER_SELECTION = $10;
}
if Succeeded(DBPrompt.PromptDataSource(nil, ParentHandle,DBPROMPTOPTIONS_PROPERTYSHEET, 0, nil, nil, IUnknown, DataSource)) then
begin
InitStr := nil;
DataInit.GetInitializationString(DataSource, True, InitStr);
NewString := InitStr;
Result := True;
end;
end;
Result:=Edit_ADO_ODBC_ConnectionString(0,OldConnectionString,NewString);
Option 2
Uses
ADODB;
PromptDataSource(Self.Handle, InitialString);
Option 3
Uses
ADODB,
AdoConEd;
procedure TMainForm.Button2Click(Sender: TObject);
Var
ADOConnection1 : TADOConnection;
begin
ADOConnection1:=TADOConnection.Create(Self);
EditConnectionString(ADOConnection1);
end;
You must Select "Microsoft OLE DB Provider for ODBC Drivers"
Bye.
这篇关于Delphi ODBC连接对话框组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!