怎么在程序中调出adoconnection的edit界面?(100分)

  • 主题发起人 主题发起人 Jeny
  • 开始时间 开始时间
J

Jeny

Unregistered / Unconfirmed
GUEST, unregistred user!
我在delphi6的demo中的ado中发现它是这样写的.
if EditConnectionString(Connection) then
begin
ConnectionString.Text := Connection.ConnectionString;
ConnectionStringClick(Sender);
end;
可editcommectionstring我编译不通过.它编译通过
怎么回事?
 
//引用ADOCONED单元。
.....
implementation

uses
AdoConEd;
......
 
implementation

uses
AdoDB;

procedure SetconnectString(var re_str:string);
begin
re_str:= PromptDataSource(application.handle,re_str);
end;
 
users
ADODB
Edit1.Text:=PromptDataSource(Handle,Edit1.Text);
这样你就把值直接付给Edit1了。
 
nod
uses adodb;
 
以下是左轻候在Rich Explorer中的一段代码
通过调用ConfigConnstr就可能了,剩下的代码你自已可
以再精简一下
unit dm;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, grids, oledb, ActiveX, comobj, olectrls, ADODB_TLB;

type
TCursorLocation = (ad_UseServer, ad_UseClient);

TParameterDirection = (ad_ParamUnknown, ad_ParamInput, ad_ParamOutput, ad_ParamInputOutput,
ad_ParamReturnValue);

TDM1 = class(TDataModule)
procedure DataModuleCreate(Sender: TObject);
private
{ Private declarations }
FQuesCount: integer;
ADOConnection1: _Connection;
DSLocal: _Recordset;
DSQues: _Recordset;
DSEdit: _Recordset;
QlistPos: integer;
ShowData: boolean;
procedure DSEditQuery(ssql: string);
procedure SaveConnStr(strConn: string);
function LoadConnStr: string;
public
{ Public declarations }
ConnStrFile: string;
sgQList: TStringGrid;
function PromptDataSource(ParentHandle: THandle; InitialString: WideString): WideString;
procedure SelectNoRoom;
function ConfigConnstr: string;
property QuesCount: integer read FQuesCount;
end;

var
DM1: TDM1;
EmptyParam: OleVariant;

const
CursorLocationValues: array[TCursorLocation] of TOleEnum = (adUseServer, adUseClient);

implementation



{$R *.DFM}

{ TDM1 }


procedure TDM1.DataModuleCreate(Sender: TObject);
begin
TVarData(EmptyParam).VType := varError;
TVarData(EmptyParam).VError := $80020004;
ShowData := false;
ADOConnection1 := CreateOleObject('ADODB.Connection') as _Connection;
DSLocal := CreateOleObject('ADODB.Recordset') as _Recordset;
DSQues := CreateOleObject('ADODB.Recordset') as _Recordset;
DSLocal.CursorType := CursorLocationValues[ad_UseServer];
DSEdit := CreateOleObject('ADODB.Recordset') as _Recordset;
end;

procedure TDM1.SelectNoRoom;
begin
// if DSLocal.Active = true then DSLocal.Close;
// ShowData := false;
end;


procedure TDM1.SaveConnStr(strConn: string);
var
sltConn: TStringlist;
begin
sltConn := TStringList.Create;
sltConn.Text := strConn;
sltConn.SaveToFile(ConnStrFile);
sltConn.free;

end;

function TDM1.LoadConnStr: string;
var
sltConn: TStringlist;
begin
sltConn := TStringList.Create;
if FileExists(ConnStrFile) then
sltConn.LoadFromFile(ConnStrFile)
else
sltConn.Text := '';

Result := sltConn.Text;
sltConn.free;

end;


procedure TDM1.DSEditQuery(ssql: string);
var
Source: OleVariant;
begin
with DSEdit do
begin
if state <> AdStateClosed then close;
Source := ssql;
Open(Source, ADOConnection1, AdOpenForwardOnly, AdLockReadOnly, adCmdText);
end;

end;




function TDM1.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;



function TDM1.ConfigConnstr: string;
begin
Result := PromptDataSource(Application.Handle, ADOConnection1.ConnectionString);
end;

end.
 
谢谢大家.
问题很久以前就解决了.现在结贴
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部