fabianmx
asked on
150 tricky points: Passing a COM Connection object
Hi,
I’m building a COM DLL in Delphi, or to be more precise, an automation server that will be called from Visual Basic code. I need to pass a COM Connection object to the Delphi DLL and then, because of compatibility issues with existing code, I need to use the connection object I received through a TADOConnection Delphi object.
Currently, I‘m receiving the COM object through an OleVariant parameter in my procedure, but I don’t know how to pass it to FConnection:
procedure TSomething.Set_COMConnecti on(COMConn : OleVariant);
var
FConnection: TADOConnection;
begin
end;
If it’s of any help, the GET function seems to be working OK:
function TSomething.Get_COMConnecti on: OleVariant;
begin
Result := FConnection.ConnectionObje ct;
end;
any ideas?
Thank you very much in advance,
F.
I’m building a COM DLL in Delphi, or to be more precise, an automation server that will be called from Visual Basic code. I need to pass a COM Connection object to the Delphi DLL and then, because of compatibility issues with existing code, I need to use the connection object I received through a TADOConnection Delphi object.
Currently, I‘m receiving the COM object through an OleVariant parameter in my procedure, but I don’t know how to pass it to FConnection:
procedure TSomething.Set_COMConnecti
var
FConnection: TADOConnection;
begin
end;
If it’s of any help, the GET function seems to be working OK:
function TSomething.Get_COMConnecti
begin
Result := FConnection.ConnectionObje
end;
any ideas?
Thank you very much in advance,
F.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello Russell,
I tried your code but it didn't work. The thing is, ConnectionObject is a read-only property, and although the project compiles without any error message, it crashes with a runtime error 8000FFFF, and a generic "Method 'COMConnection' of object 'ISomething' Failed"
However, the condition
if (IUnknown(COMConn).QueryIn terface(_C onnection, _c) = S_OK) then
evaluated as TRUE, yet I still can't pass it to FConnection
I tried your code but it didn't work. The thing is, ConnectionObject is a read-only property, and although the project compiles without any error message, it crashes with a runtime error 8000FFFF, and a generic "Method 'COMConnection' of object 'ISomething' Failed"
However, the condition
if (IUnknown(COMConn).QueryIn
evaluated as TRUE, yet I still can't pass it to FConnection
ASKER
Hi Russell,
Nevermind my last comment, the code worked perfectly, it's just that I forgot to intialize the TADOConnection object FConnection.
As usual an excellent answer.
AvonWyss, I'm giving the points to Russell because he offered a working solution first. Although your code is neater I'd rather stick to Russell's because since I'm a novice Delphi programmer I'd rather have the code as explicit as possible.
Thanx anyway,
F.
Nevermind my last comment, the code worked perfectly, it's just that I forgot to intialize the TADOConnection object FConnection.
As usual an excellent answer.
AvonWyss, I'm giving the points to Russell because he offered a working solution first. Although your code is neater I'd rather stick to Russell's because since I'm a novice Delphi programmer I'd rather have the code as explicit as possible.
Thanx anyway,
F.
FConnection.ConnectionObje
This eliminates the need for the manual QueryInterface() call and the exception raising if the type is not correct, and it does look more Delphi-like.