由于ActiveForm中要用到Indy的IdTCPClient和服务端的程序用IdTCPServer连接,需要知道服务器的IP地址。服务端的程序是用IdHTTPServer1做网络访问服务的。

解决方案 »

  1.   

    uses
      ActiveX,MSHtml;
    //在ActiveForm中调用,参数x就是 selffunction GetCurrentPageUrl(x : TActiveForm): String;
    var
      i_hd : IHTMLDocument2;
      i_oc : IOleContainer;
    begin
      Result:='';
      try
        if (x.ActiveFormControl.ClientSite.GetContainer(i_oc) = S_OK) and
           (i_oc.QueryInterface(IHTMLDocument2, i_hd) = S_OK) then
        begin
          Result:=String(i_hd.location.href); 
          //如果你熟悉javascript的话,i_hd.location.href很容易理解...
        end
        else
          Exit;
      except
        Exit;
      end;
    end;
      

  2.   

    如果你熟悉javascript的话,i_hd.location.href很容易理解...需要知道服务器的IP地址、端口等:
    i_hd.location.host
    i_hd.location.port
    ...
    ...
      

  3.   


    服务端用的是IdHTTPServer!
    这两个条件不成立
        if (x.ActiveFormControl.ClientSite.GetContainer(i_oc) = S_OK) and
           (i_oc.QueryInterface(IHTMLDocument2, i_hd) = S_OK) theni_hd.location.host 得到是空的。
      

  4.   

    我给的代码适用于ActiveForm嵌在Web页面中,并通过IE访问的情况,
    不太明白,你的ActiveForm如何使用的?
      

  5.   

    是通过IE访问的,用的是DEPHI自动生成的Index.htm.
      

  6.   

    FDocument.location.host  就是啊
      

  7.   

    不好意思,FDocument.location.host也是空的。
    服务端的程序是用IdHTTPServer的。