想问下为什么,,我动态创建了一组IDHTTP,用来获取一组网页源代码.会奇卡无比(在多线程中) ? 经过几十秒后,才显示出来.⒈我没有使用临界区⒉参数: idweb.ReadTimeout:= 30000; 就设置这一个⒊使用: memo1.text:=idweb.get(weburl);相关代码:var
weburl:string;function ipscan.checkweb(url:string):string;
var
idweb:TIdHTTP;
value:string;
begin
idweb:=Tidhttp.Create(nil);
idweb.ReadTimeout:= 30000;
try
 try
value:=idweb.get;
except
idweb.Free;
end;
finally
idweb.Free;…

解决方案 »

  1.   

    把线程类的代码贴上来。看看是不是在线程的Execute当中执行。
      

  2.   


    unit ipscanthread;interfaceuses
      Classes, StdCtrls, dialogs,SysUtils, ComCtrls, Windows, idtcpclient,IdHTTP,WinInet;
    var
    CS:TRTLCriticalSection;    //定义全局临界区type
      ipscan = class(TThread)
      private
        ipUrl:string;
        ViewList:TTreeview;
        { Private declarations }
      protected
        procedure Execute; override;
        function CheckUrl(const Url: string):boolean;
        procedure ViewInfo();
        function  checkweb(ip:string):string;
      public
        constructor Create(hurl:string;vlist:TTreeview);
      end;
    implementation
    uses unit1;constructor ipscan.Create(hurl:string;vlist:TTreeview);  //取id!!
    begin
      ipUrl:=hurl;
      ViewList:=vlist;
      FreeOnTerminate := True;
      inherited create(false);
    end;function ipscan.checkweb(web:string):string;
    var
    idweb:TIdHTTP;
    value:string;
    begin
    idweb:=Tidhttp.Create(nil);
    idweb.ReadTimeout:= 30000;
    try
      try
       Values:= Idweb.Get(web);
       except idweb.Free;
       end;
      finally
        idweb.Free;
      end;
    result:=web;
    end;function  ipscan.CheckUrl(const Url: string):boolean;
    var
    idping:TIdTCPClient;
    begin
    result:=false;
    idping:=TidTCPClient.Create(nil);
    idping.Port:=80;
    idping.Host:=Url;
    try
      try
       idping.Connect(5000);
       if idping.Connected then result:=true;
       except idping.Disconnect;
    end;
      finally
        idping.Free;
      end;
    end;procedure ipscan.ViewInfo();
    begin
    viewlist.Items.Add(nil,ipurl);
    memo1.lines.add(checkweb(ipurl));
    end;procedure ipscan.Execute;
    begin
      if CheckUrl(ipUrl) then
      begin
        Synchronize(ViewInfo);
      end;
    end;
    先ping 80端口是否开放,如果开放将获取源代码.
      

  3.   

    unit ipscanthread;interfaceuses
      Classes, StdCtrls, dialogs,SysUtils, ComCtrls, Windows, idtcpclient,IdHTTP,WinInet;
    var
    CS:TRTLCriticalSection;    //定义全局临界区type
      ipscan = class(TThread)
      private
        ipUrl:string;
        ViewList:TTreeview;
        CheckResult: String;
        { Private declarations }
      protected
        procedure Execute; override;
        function CheckUrl(const Url: string):boolean;
        procedure ViewInfo();
        function  checkweb(ip:string):string;
      public
        constructor Create(hurl:string;vlist:TTreeview);
      end;
    implementation
    uses unit1;constructor ipscan.Create(hurl:string;vlist:TTreeview);  //取id!!
    begin
      ipUrl:=hurl;
      ViewList:=vlist;
      FreeOnTerminate := True;
      inherited create(false);
    end;function ipscan.checkweb(web:string):string;
    var
    idweb:TIdHTTP;
    value:string;
    begin
    idweb:=Tidhttp.Create(nil);
    idweb.ReadTimeout:= 30000;
    try
      try
       Values:= Idweb.Get(web);
       except idweb.Free;
       end;
      finally
        idweb.Free;
      end;
    result:=web;
    end;function  ipscan.CheckUrl(const Url: string):boolean;
    var
    idping:TIdTCPClient;
    begin
    result:=false;
    idping:=TidTCPClient.Create(nil);
    idping.Port:=80;
    idping.Host:=Url;
    try
      try
       idping.Connect(5000);
       if idping.Connected then result:=true;
       except idping.Disconnect;
    end;
      finally
        idping.Free;
      end;
    end;procedure ipscan.ViewInfo();
    begin
    viewlist.Items.Add(nil,ipurl);
    //memo1.lines.add(checkweb(ipurl));
    Memo1.Lines.Add(CheckResult);
    end;procedure ipscan.Execute;
    begin
      if CheckUrl(ipUrl) then
      begin
        CheckResult := checkweb(ipurl);
        Synchronize(ViewInfo);
      end;
    end;
      

  4.   

    谢谢 但是编译时出现:Statement expected, but expression of type 'String' found