我用ActiveForm做了一个B/S程序,后台用SQL Server 2000数据库,现在我是把服务器地址直接写到代码中了,如:ADOQuery.ConnectionString='SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=123;Initial Catalog=test;Data Source=192.168.1.98,但这样做不灵活,不同的用户的服务器地址肯定不一样,我怎么才能获得ActiveForm所在网页中的IP地址呢? 最好有例子,谢谢!

解决方案 »

  1.   

    使用参数(属性)来传递,记得加密,如用ASP、CGI等调用。
    当然这种的局限性还是比较大的,比如使用端口映射,之后,就几近无法使用。
      

  2.   

    那怎么才知道IE浏览器当中当前的地址,并且Delphi怎样取这个地址?
      

  3.   

    我还想要取网页的TITLE以及他的网址,哪位高手帮帮忙呀。
      

  4.   

    这个问题我已经回答过很多次了,呵呵:http://community.csdn.net/Expert/topic/4212/4212032.xml?temp=.6411096------------------------------
    稍微改一下:
    Result:=String(i_hd.location.href);
    变成
    Result:=String(i_hd.location.hostname);
    ------------------------------function 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);
        end
        else
          Exit;
      except
        Exit;
      end;
    end;
      

  5.   

    我给楼主一个吧,完整的代码哦,接分,嘿嘿........unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls, StdCtrls;type
      TForm1 = class(TForm)
        Edit1: TEdit;
        Button1: TButton;
        Timer1: TTimer;
        procedure Timer1Timer(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;  function EnumChildProc(hwnd:HWND;IParam:LPARAM):bool;stdcall;
    var
      Form1: TForm1;  strUrl:string;
    implementation{$R *.dfm}function EnumChildProc(hwnd:HWND;IParam:LPARAM):bool;stdcall;
      var buf:array[0..250] of char;
      rsize:integer;
      str:string;
    begin
      result:=true;
      Getclassname(hwnd,buf,sizeof(buf));
      if strpas(buf)='Edit' then
       begin
         rsize:=sendmessage(hwnd,WM_GETTEXT,sizeof(buf),integer(@buf));
         if rsize>0 then
         begin
           strUrl:=buf;    //这就是当前打开页面的URL
         end;
       end;
    end;
    procedure TForm1.Timer1Timer(Sender: TObject);
    var
     fwnd,hwnd:thandle;
     buf2,buf:array[0..250] of char;
      begin
        fwnd:=GetForegroundWindow;
        hwnd:=fwnd;
        Getclassname(fwnd,buf,sizeof(buf));
        EnumChildWindows(fwnd,@enumchildproc,0);
        Edit1.text := strUrl;  end;end.