Delphi 与 html 交互数据操作

最近在项目中,需要对html文件中的JS 函数,并返回数据结果;

function Tfrmgis.InvokeScript(Doc: IHTMLDocument2; aName,
  aParam: string): Variant;
  var
  Disp : IDispatch;
  Member : WideString;
  TheDispId : Integer;
  DisParam:TDispParams;
  VariantArg : TVariantArg;
  Args : WideString;
begin
   Disp:=(Doc   as   IHTMLDocument).Script;
   if Disp <> nil then
   begin
     Member:=aName;
     if (Disp.GetIDsOfNames(GUID_NULL,@Member,1,LOCALE_SYSTEM_DEFAULT,@TheDispId))=S_OK then
     begin
         FillChar(DisParam,SizeOf(DispParams),0);
         FillChar(VariantArg,   SizeOf(VariantArg),   0);
         DisParam.cArgs:=1;
         DisParam.rgvarg    :=   @VariantArg;
         Args               :=   aParam;
         VariantArg.bstrVal :=   pointer(Args);
         OleCheck(Disp.Invoke(TheDispId,GUID_NULL,0,DISPATCH_METHOD,DisParam,@Result,nil,nil));
     end;

   end;
end;

调用函数;

procedure Tfrmgis.btreviewClick(Sender: TObject);
var
 data : string;
 Doc  :   IHTMLDocument2;
begin
   
  if   Supports(WebBrowser1.Document,   IHTMLDocument2,   Doc) then
  begin
     data := InvokeScript( doc,'getPoint','');

     if not string.IsNullOrEmpty(Data) then
     begin
       data := LeftStr(data,Length(data)-1);
       
     end;
      
  end;
end;

 

其中,为js 函数;引用的单元文件:Winapi.ActiveX,System.StrUtils; 引用地址:http://www.360doc.com/content/11/1118/10/7662927_165403499.shtml

 

其他的一些常见交互操作:

https://blog.csdn.net/iseekcode/article/details/4740269

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值