下面是部分代码。程序运行后,如果网页内容较多,或较大,会出现记时停顿的现象,如何能让网页打开的同时,记时显示不停顿呢?
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleCtrls, SHDocVw, StdCtrls, ExtCtrls;type
  TForm1 = class(TForm)
    Button1: TButton;
    Timer1: TTimer;
    Label1: TLabel;
    WebBrowser1: TWebBrowser;
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;
  T : integer = 0;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
   WebBrowser1.Navigate('http://darksun2008.blog.sohu.com/');
end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
   T := T + 1;
   Label1.Caption := inttostr(T);
end;end.

解决方案 »

  1.   

    只有一个主线程当然会这样.
    下面就是多线程的例子.你把代码放进那个MyThreadFunc里执行就行了.unit MyThreadPro;
    interface
    uses
      Windows, Messages, SysUtils, Classes, 
      Graphics, Controls, Forms, Dialogs,StdCtrls;
    type
      TForm1 = class(TForm)
        UsedThread: TButton;
        NoUsedThread: TButton;
        procedure UsedThreadClick(Sender: TObject);
        procedure NoUsedThreadClick(Sender: TObject);
    var
      Form1: TForm1;implementation
    {$R *.DFM}
    //这是线程函数,它可以放在下面程序的任何地方
    function MyThreadFunc(P:pointer):Longint;stdcall;
    var
      i:integer;
      DC:HDC;
      S:string;
    begin
      DC:=GetDC(Form1.Handle);
      for i:=0 to 100000 do begin
        S:=Inttostr(i);
        Textout(DC,10,10,Pchar(S),length(S));
      end;
      ReleaseDC(Form1.Handle,DC);
    end;procedure TForm1.UsedThreadClick(Sender: TObject);
    var
       hThread:Thandle;//定义一个句柄
       ThreadID:DWord;
    begin
      //创建线程,同时线程函数被调用
      hthread:=CreateThread(nil,0,
        @MyThreadfunc,nil,0,ThreadID);
      if hThread=0 then messagebox(
        Handle,'Didn’t Create a Thread',nil,MB_OK);
    end;procedure TForm1.NoUsedThreadClick(Sender: TObject);
    begin
      MyThreadfunc(nil); 
      //没有创建线程时,直接调用线程函数
    end;end.
      

  2.   

    //这是线程函数,它可以放在下面程序的任何地方
    function MyThreadFunc(P:pointer):Longint;stdcall; 
    /////////////////////////////////////////////////////////////////////////////////////
    感谢回复,这个实例子我搜索到了,但是我不会写这个函数,能指点的再详细点么?另外我在网上还搜索到了一个这样的例子:
    unit Unit2;interfaceuses
      Classes,Forms,Windows;type
      TMyThread = class(TThread)
      private
        { Private declarations }
        procedure Run;
      protected
        procedure Execute; override;
      end;implementationuses Unit1;
    { Important: Methods and properties of objects in visual components can only be
      used in a method called using Synchronize, for example,      Synchronize(UpdateCaption);  and UpdateCaption could look like,    procedure TMyThread.UpdateCaption;
        begin
          Form1.Caption := 'Updated in a thread';
        end; }{ TMyThread }procedure TMyThread.Execute;
    begin
      //ExitThread(0);
      Self.Synchronize(Run);
    end;procedure TMyThread.Run;
    begin
        with Form1 do
           begin
            WebBrowser2.Navigate('http://darksun2008.blog.sohu.com/');
            Application.ProcessMessages;
           end;
    end;end.
    但是执行起来还是有记时停顿的现象,我是菜鸟,请前辈能指点清楚,或给个实用的代码好么,感谢!