本文介绍了从vba到delphi的传递adoconnection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在VBA宏中创建一个COM对象,然后将其传递给Delphi DLL(D2009)。我在Delphi中的过程声明应该是什么样子?

I'm looking to create a COM object in a VBA macro and then pass it to a Delphi DLL (D2009). What should my procedure declaration in Delphi look like?

背景:
我期望VBA宏到:
创建COM对象,
调用Delphi DLL,
将COM对象传递给Delphi DLL过程,
保持活动状态,直到Delphi DLL关闭本身(该DLL将嵌入表单供用户交互)。

Background:I'm expecting (hoping) the VBA macro to: create the COM object, invoke the Delphi DLL, pass the COM object to the Delphi DLL procedure, stay alive until the Delphi DLL closes itself (the DLL will have embedded forms for the user to interact with).

我想我需要创建一个回调函数让VBA宏知道我已经完成了所以它可以整理,但我会独立工作

I think I'll need to create a callback function to let the VBA macro know that I'm done so it can tidy up but I'll work on that independently of this question.

UPDATE
更具体地说:导出的函数声明应该用于Delphi DLL。

UPDATEMore specifically: What should the exported function declaration be for the Delphi DLL.

推荐答案

您必须传递ADO连接接口链接 _Connection 到delphi过程
然后创建TADOConnection实例并替换ConnectionObject新界面链接

you have to pass ADO Connection interface link _Connection to delphi procedurethen create TADOConnection instance and replace ConnectionObject with new interface link

library Project1;
uses ADODB;

{$R *.res}

    procedure SetConnection(aDBConnection : _Connection);  stdcall;
    var connect : TADOConnection;
    begin
        connect := TADOConnection.Create(nil);
        try
            connect.ConnectionObject := aDBConnection;
            //here you can use your connection
        finally
            connect.Free();
        end;
    end;


exports SetConnection name 'SetDBConnection';

begin
end.

最好使用 stdcall 调用约定。使用 export 关键字 setConnection proc可从u开始使用 SetDBConnection name,所以你可以 LoadLibrary 和 getProcAddress 找到它的入口点(真的我不知道VBA, 't说如何加载库使用它)

it is better to use stdcall calling convention. using export keyword setConnection proc is available from uotside with SetDBConnection name , so you can LoadLibrary and getProcAddress to find its entry point (really I don't know VBA so I can't say how to load library using it)

这篇关于从vba到delphi的传递adoconnection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 21:44