js通过window.external调用delphi的返回值类型问题解决方案,不解的COM问题

  最近做一个软件,用webbrowser做软件界面,通过js的window.external调用delphi的函数实现数据库操作等功能,在需要返回值的时候,遇到问题了,来源如下图:

在接口中加入一方法,传入参数为BSTR(wideString)类型,希望返回VARIANT(OLEVariant),自动生成的函数结构如下:

  在***_TLB.pas中:

 

Itest = interface(IDispatch)
['{D9941302-C827-4517-ADA0-003D176E9E9A}']
function Method1(const a: WideString): OleVariant; stdcall;
end;

 

 在接口实现单元中:

 

type
Ttest = class(TAutoObject, Itest)
protected
function Method1(const fd: WideString): OleVariant; stdcall;

end;

implementation

uses ComServ;

function Ttest.Method1(const fd: WideString): OleVariant;
begin

end;

 

运行后,在网页中调用:

  

var a=window.external.Method1('fdsa');
alert(a);
 
 
执行时,报错;
纠结很久,对函数重新申明如下图:

 

在***_TLB.pas中:

Itest = interface(IDispatch)
['{D9941302-C827-4517-ADA0-003D176E9E9A}']
function Method1(const a: WideString): OleVariant; safecall;
end;

在接口实现单元中:

  Ttest = class(TAutoObject, Itest)
protected
function Method1(const a: WideString): OleVariant; safecall;

end;

implementation

uses ComServ;

function Ttest.Method1(const a: WideString): OleVariant;
begin

end;


运行后可正常显示返回内容,对于我这种菜鸟来说,唯一的区别就是safecallstdcall, 由于没有程序基础,用delphi全靠自学,不太明白这两个东西的区别,暂时不管他,只要程序能工作就行,在这里做个记录,以免再犯错。


 

转载于:https://www.cnblogs.com/Delphi-Farmer/archive/2012/02/11/2346935.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值