双击adoconnection对象时,将出现一个对话框,设置对话框将产生一个连接字符串(widestring类型),我想通过调用ADO的原生对象来调用这个对话框进而得到连接字符串。看了一下delphi类的元代码:
//这个返回连接字符串
function TADOConnection.GetConnectionString: WideString;
begin
if (csWriting in ComponentState) and Connected then
Result := FConnectionString
else
Result := ConnectionObject.ConnectionString;
end;
最后一句是关键的调用,再看ConnectionObject在adodb.pas 的应用
property ConnectionObject: _Connection read FConnectionObject write SetConnectionObject;
是一个_Connection型,并且通过SetConnectionObject得到。
到这里就不明白了:
procedure TADOConnection.SetConnectionObject(const Value: _Connection);
procedure TADOConnection.CheckInactive;
begin
{ At design time, force connection to be closed as needed }
if Connected and (csDesigning in ComponentState) then
Close;
end;
begin
CheckInActive;
if Assigned(Value) then
begin
OleCheck(ConnectionPoint.UnAdvise(FConnEventsID));
FConnectionObject := Value;
OleCheck(ConnectionPoint.Advise(Self as IUnknown, FConnEventsID));
end;
end;
一头雾水,如果用原生对象,怎么写代码呢?
//这个返回连接字符串
function TADOConnection.GetConnectionString: WideString;
begin
if (csWriting in ComponentState) and Connected then
Result := FConnectionString
else
Result := ConnectionObject.ConnectionString;
end;
最后一句是关键的调用,再看ConnectionObject在adodb.pas 的应用
property ConnectionObject: _Connection read FConnectionObject write SetConnectionObject;
是一个_Connection型,并且通过SetConnectionObject得到。
到这里就不明白了:
procedure TADOConnection.SetConnectionObject(const Value: _Connection);
procedure TADOConnection.CheckInactive;
begin
{ At design time, force connection to be closed as needed }
if Connected and (csDesigning in ComponentState) then
Close;
end;
begin
CheckInActive;
if Assigned(Value) then
begin
OleCheck(ConnectionPoint.UnAdvise(FConnEventsID));
FConnectionObject := Value;
OleCheck(ConnectionPoint.Advise(Self as IUnknown, FConnEventsID));
end;
end;
一头雾水,如果用原生对象,怎么写代码呢?
谢谢smilefox2000。
不过已知道用CreateComObject()创建Connection对象。
创建完成后在调用Connection的方法,那个方法呢?