当前位置: 首页 > 图文教程 > 开发语言 > Delphi > 用Delphi检测IE使用的代理服务器

Delphi
得到执行程序的目录
返回程序执行参数
如何区分3种不同的FormActive事件
正确关闭一个MDI子窗口
写小执行程序
替换指定串函数
动态数组
动态产生构件并相应事件
文件管理(一)
想成高手吗?快来学Delphi快捷键
浅谈Delphi如何控制Excel操作
用Delphi检测IE使用的代理服务器
Delphi学习:查句柄知多少
Delphi学习:OOP 中的双刃剑
在 NT内核的操作系统上实现系统关闭
用Delphi制作DLL的方法
Delphi:Daily build实践
Delphi控制Excel的重要属性和方法
Delphi学习:2个不错的通配符比较函数
字符串分割扩展 SplitEx

用Delphi检测IE使用的代理服务器


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-30   浏览: 42 ::
收藏到网摘: n/a

 
如果我们开发的对象,不是在公网的环境内上网,是使用内网的,我们应该怎么样检测你的IE使用的代理服务器呢?接下来我们通过以下实例来学习:
  



  //-----------------------------------------------
  //记得引用 WinInet 单元
  //-----------------------------------------------
  uses
  WinInet

  //----------------------------------------------
  //定义要使用的函数
  //----------------------------------------------

  function GetProxyInformation: string;
  var
  ProxyInfo: PInternetProxyInfo;
  Len: LongWord;
  begin
  Result := '';
  Len := 4096;
  GetMem(ProxyInfo, Len);
  try
  if InternetQueryOption(nil, INTERNET_OPTION_PROXY, ProxyInfo, Len) then
  if ProxyInfo^.dwAccessType = INTERNET_OPEN_TYPE_PROXY then
  begin
  Result := ProxyInfo^.lpszProxy
  end;
  finally
  FreeMem(ProxyInfo);
  end;
  end;

  procedure GetProxyServer(protocol: string; var ProxyServer: string;
  var ProxyPort: Integer);
  var
  i: Integer;
  proxyinfo, ps: string;
  begin
  ProxyServer := '';
  ProxyPort := 0;

  proxyinfo := GetProxyInformation;
  if proxyinfo = '' then
  Exit;

  protocol := protocol + '=';



  i := Pos(protocol, proxyinfo);
  if i > 0 then
  begin
  Delete(proxyinfo, 1, i + Length(protocol));
  i := Pos(';', ProxyServer);
  if i > 0 then
  proxyinfo := Copy(proxyinfo, 1, i - 1);
  end;

  i := Pos(':', proxyinfo);
  if i > 0 then
  begin
  ProxyPort := StrToIntDef(Copy(proxyinfo, i + 1, Length(proxyinfo) - i), 0);
  ProxyServer := Copy(proxyinfo, 1, i - 1)
  end
  end;
  //----------------------------------------------------------------
  //使用范例
  //----------------------------------------------------------------
  procedure TForm1.Button1Click(Sender: TObject);
  var
  ProxyServer: string;
  ProxyPort: Integer;
  begin
  GetProxyServer('http', ProxyServer, ProxyPort);
  if  ProxyPort=0 then
  begin
  ShowMessage('你的IE没有使用的代理服务器')
  end
  else
  Label1.Caption := ProxyServer;
  label2.Caption := IntToStr(ProxyPort);

  end;