2012-07-17 39 views
1

我正在准备申请。 IDHTTP:使用Get方法。但是有一些问题。我想创建一个代理列表并单击列表框项目(代理地址)IDHTTP添加。对不起,我很少认识英语。从列表框中选择代理(IDHTTP)

我的代码;

procedure TForm1.CheckBox1Click(Sender: TObject); 
begin 
if CheckBox1.Checked then 
begin 
LabeledEdit1.Enabled:= true; 
LabeledEdit2.Enabled:= true; 
IdHTTP1.ProxyParams.ProxyServer:=LabeledEdit1.Text; 
IdHTTP1.ProxyParams.ProxyPort:=StrToInt(LabeledEdit2.Text); 

CheckBox1.Caption:='Kendi IP adresimi kullan.'; 

end 
else 
begin 

LabeledEdit1.Enabled:= false; 
LabeledEdit2.Enabled:= false; 
IdHTTP1.ProxyParams.ProxyServer:=''; 
IdHTTP1.ProxyParams.ProxyPort:=StrToInt('0'); 

CheckBox1.Caption:='Proxy kullan.'; 

end; 
end; 

procedure TForm1.BitBtn2Click(Sender: TObject); 
begin 
IdHTTP1.Get(Edit1.Text); 
MessageDlg('Mission complated.', mtinformation,[mbOK],0); 
end; 

我想要;

我添加Listbox1代理..稍后..点击Listbox1项目。稍后.. BitBtn2点击。

谢谢。

+1

你已经有了逻辑需要指定一个代理服务器'TIdHTTP',那么什么是您所遇到的实际问题?在分配代理信息时,只需将代码更改为使用“TListBox”而不是“TLabeledEdit”。 – 2012-07-17 23:47:25

+0

@RemyLebeau,我*想*问题是关于如何将所有可用的代理服务器添加到列表框,并允许用户从列表框中选择'TIdHTTP.ProxyParams'中使用的代理服务器。 – 2012-07-18 00:36:29

+0

有很多代理。 1.1.x.2.1:80,1.2.x.x.5:60 .....作为一个一个来避免? Listbox1.itemadd(Proxy +:+ Port)as?...对不起。 – user1424940 2012-07-18 00:46:42

回答

3
Listbox1.Items.Add('1.1.x.2.1:80'); 
Listbox1.Items.Add('1.2.x.x.5:60'); 
... 

procedure TForm1.Listbox1Click(Sender: TObject); 
var 
    I: Integer; 
    S: String; 
begin 
    I := Listbox1.ItemIndex; 
    if I <> -1 then 
    begin 
    S := Listbox1.Items[I]; 
    IdHTTP1.ProxyParams.ProxyServer := Fetch(S, ':'); 
    IdHTTP1.ProxyParams.ProxyPort := StrToInt(S); 
    end 
    else 
    begin 
    IdHTTP1.ProxyParams.ProxyServer := ''; 
    IdHTTP1.ProxyParams.ProxyPort := 0; 
    end; 
end; 

procedure TForm1.BitBtn2Click(Sender: TObject);   
begin   
    IdHTTP1.Get(Edit1.Text);   
    MessageDlg('Mission complated.', mtinformation,[mbOK],0);   
end;  
+0

谢谢,但.. [Error] Unit1.pas(139):Undeclared标识符:'Fetch'错误? – user1424940 2012-07-18 08:34:58

+0

@ user1424940你基本上以“ip:port”的形式解析字符串,所以你需要抓取ip,“:”之前的部分,然后是端口,“:”之后的部分,在“s”变量之前的所有内容并在“:”后面留下该部分,同时倾倒它,这是一个很好的练习。 – ComputerSaysNo 2012-07-18 12:04:38

+0

我添加了IdGlobal使用。问题解决了。如果错误407然后showmessage()? – user1424940 2012-07-18 12:09:19