请问在Delphi使用COM时,怎样使用out参数?例如:
在VC中编写的COM有如下接口:
STDMETHOD(aaa)(/*[in]*/long a1,/*[out]*/long *a2);STDMETHODIMP CDBMgr::aaa(long a1, long *a2)
{
*a2 = a1;
}在Delphi的*_tlb.pas中自动生成如下定义:
procedure aaa(a1: Integer; out a2: Integer);
请问怎样使用这个接口?在用如下方法调用时,出现错误:Project bbb.exe raised exception class EAccessViolation with message 'Access violation at address 00000000.Read of address 00000000',Process stopped.Use Step or Run to continue.
var
addr:integer;
begin
DBMgr.aaa(1,addr);
end;
在VC中编写的COM有如下接口:
STDMETHOD(aaa)(/*[in]*/long a1,/*[out]*/long *a2);STDMETHODIMP CDBMgr::aaa(long a1, long *a2)
{
*a2 = a1;
}在Delphi的*_tlb.pas中自动生成如下定义:
procedure aaa(a1: Integer; out a2: Integer);
请问怎样使用这个接口?在用如下方法调用时,出现错误:Project bbb.exe raised exception class EAccessViolation with message 'Access violation at address 00000000.Read of address 00000000',Process stopped.Use Step or Run to continue.
var
addr:integer;
begin
DBMgr.aaa(1,addr);
end;
可能因为addr是本地变量
被优化掉了
从COM中传出的数据使用了这个地址
但优化后的数据是无效的地址
试着用const addr
或全局变量来做out
STDMETHODIMP CDBMgr::aaa(long a1, long *a2)
{
*a2 = a1;
// return S_OK;
}