// 要做的工作很简单,就是用IdHttp打开一个网页,然后用Doc(IHTMLDocument2)
// 来分析抓取一些数据,代码运行正常。但是由于比较费时,所以想用线程来做,
// 可是改成线程后下面的Application.ProcessMessages老是跳不出循环
procedure TForm1.Button1Click(Sender: TObject);
var
  s: string;
begin
  s := idhttp1.Get('http://www.baidu.com');  // 随便举个例子
  WB_LoadHTML(Doc, s);  // 把
  while Doc.ReadyState <> 'complete' do
    Application.ProcessMessages;//--------------> 假如线程中能走到此处就算解决了
//  ParseHtml;
end;
整个程序的代码简化如下:
http://www.justlamps.us.com/
http://tw.stock.yahoo.com/s/list.php?c=tse&rr=11629791662960.36638015953042296
http://tw.stock.yahoo.com/s/list.php?c=otc&rr=11665957725150.010428710095903737http://money.hinet.net/stock/z00.htm?A=/z/choice.htmunit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdHTTP, MsHtml;type
  TForm1 = class(TForm)
    IdHTTP1: TIdHTTP;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    Doc: IHTMLDocument2;
  end;var
  Form1: TForm1;implementation{$R *.dfm}uses activex, StrUtils, ComObj;procedure WB_LoadHTML(IDoc: IHtmlDocument2; HTMLCode: string);
var
  sl: TStringList;
  ms: TMemoryStream;
begin
  sl := TStringList.Create;
  try
    ms := TMemoryStream.Create;
    try
      sl.Text := HTMLCode;
      sl.SaveToStream(ms);
      ms.Seek(0, 0);
      (IDoc as IPersistStreamInit).Load(TStreamAdapter.Create(ms));
    finally
      ms.Free;
    end;
  finally
    sl.Free;
  end;
end;// 要做的工作很简单,就是用IdHttp打开一个网页,然后用Doc(IHTMLDocument2)
// 来分析抓取一些数据,代码运行正常。但是由于比较费时,所以想用线程来做,
// 可是改成线程后下面的Application.ProcessMessages老是跳不出循环
procedure TForm1.Button1Click(Sender: TObject);
var
  s: string;
begin
  s := idhttp1.Get('http://www.baidu.com');  // 随便举个例子
  WB_LoadHTML(Doc, s);  // 把
  while Doc.ReadyState <> 'complete' do
    Application.ProcessMessages;//--------------> 假如线程中能走到此处就算解决了
//  ParseHtml;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
  Doc := CreateComObject(Class_HTMLDOcument) as IHTMLDocument2;
end;end;end.

解决方案 »

  1.   

    在线程里将Application.ProcessMessages;改为
        Sleep(50);
      

  2.   


    while Doc.ReadyState  <>  'complete' do 
        Application.ProcessMessages; 
    注释掉
      

  3.   

    同意:
    在线程里将Application.ProcessMessages;改为
        Sleep(50);
      

  4.   

    我想问题可能在于IPersistStreamInit,你搜搜相关的文章
      

  5.   

    1。线程内不允许使用Application.ProcessMessages。
    2。注意:有些类不能在线程内正常运行。
      

  6.   

    Application.ProcessMessages不能用在线程里面
      

  7.   

    首先线程中可以使用Application.ProcessMessages,我的采集程序中就使用了.
    我认为你的线程可能有问题,有些对像是线程不安全的.要使用Synchronize