- Delphiartiklar, tips, forum, länksamling - 

      

START | DELPHI | LÄNKARGÄSTBOK 




 Forum

Grundkurs
  »Introduktion
  »Snabbguide
  »Komponenter
  »Händelser
  »Strängar
  »Räkna med Delphi   »Egna typer
  »Selektion
  »Iteration
  »Menyer
  »Funktioner
  »Arraystrukturer

Tips & Tricks
  »Nya tips
  »Blandat
  »Databaser
  »Filer
  »Forms
  »Grafik
  »Internet
  »Komponenter
  »Matematik
  »Multimedia
  »Objekt/ActiveX
  »Skrivare
  »Strängar
  »System
  »Mest lästa tips

Artiklar
  »Delphi och ADO
  »Bygga en DLL
  »Skapa en enkel rapport
  »Hantera registret
  »Enheter, units
  »Klassen TCanvas
  »Använd LookUp Controls

 Nya tips
 Lägg till tips
 Delphilänkar
 Gästbok

 

Upptäck en HTTP Proxy Kategori: Internet
Inlagt: 2005-03-24
Läst: 1754
Inlagt av: Staffan Berg
Beskrivning
Följande exempel returnerar värdnamnet, portnumret och om en proxy är tillgänglig.
Kod
unit fProxy; 
 
interface 
 
uses 
 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Registry; 
 
type 
 TForm1 = class(TForm) 
  procedure FormCreate(Sender: TObject); 
 private 
  { private declarations } 
 public 
  { public declarations } 
 end; 
 
var 
 Form1: TForm1; 
 
implementation 
 
{$R *.DFM} 
 
function GetProxy(var Host : string ; var Port : integer; var ProxyEnabled : boolean) : boolean; 
const 
 sProxyEnable = 'ProxyEnable'; 
var 
 s : string ; 
 p : integer; 
begin 
 with TRegistry.Create do 
 begin 
  RootKey := HKEY_CURRENT_USER; 
  ProxyEnabled := false; 
  s := ''; 
  OpenKey ('\Software\Microsoft\Windows\CurrentVersion\Internet Settings', True); 
  if ValueExists('ProxyServer') then 
   s := ReadString('ProxyServer'); 
 
  if s <> '' then 
  begin 
   p := pos(':', s); 
   if p=0 then 
    p := length(s)+1; 
   Host := copy(s, 1, p-1); 
   try 
    Port := StrToInt(copy (s,p+1,999)); 
   except 
    Port := 80; 
   end; 
 
   ProxyEnabled := true; 
  end; 
 
  if ValueExists('ProxyEnable') then 
  begin 
    case GetDataType(sProxyEnable) of 
    rdString, 
    rdExpandString: 
    begin 
     sPortTmp := AnsiLowerCase(ReadString(sProxyEnable)); 
     ProxyEnabled := true; 
     if pos(' '+sPortTmp+' ', ' yes true t enabled 1 ') > 0 then 
      ProxyEnabled := true 
     else 
     if pos(' '+sPortTmp+' ', ' no false f none disabled 0 ') > 0 then 
      ProxyEnabled := false 
    end; 
    rdInteger: 
    begin 
     ProxyEnabled := ReadBool(sProxyEnable); 
    end; 
    rdBinary: 
    begin 
     ProxyEnabled := true; 
     ReadBinaryData(sProxyEnable, ProxyEnabled, 1); 
    end; 
    end; 
  end; 
 
  Free; 
 end; 
 
 Result := s<>''; 
end; 
 
procedure TForm1.FormCreate(Sender: TObject); 
var 
 Host : string ; 
 Port : integer; 
 ProxyEnabled : boolean; 
const 
 YesNo : array [false..true] of string = (' not ', ''); 
begin 
 // get proxy information 
 if GetProxy(Host, Port, ProxyEnabled) then 
  ShowMessage(Format('Your proxy is %s on port %d, it is%s enabled.', [Host, Port, YesNo[ProxyEnabled]])) 
 else 
  ShowMessage('No proxy detected'); 
end; 
 
end. 

 
 
© Copyright 2005 - Staffan Berg
- Alla rättigheter förbehålles -