下面是部分代码。程序运行后,如果网页内容较多,或较大,会出现记时停顿的现象,如何能让网页打开的同时,记时显示不停顿呢?
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.
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.
解决方案 »
- 我可以告诉你一个秘密:
- Delphi里有没有类似C里#define的命令?
- 如何判断idftp客户端与server是否相连,好象用idftp1.ClosedGracefully来判断不行啊!!!!(急) (
- 有关用InstallShield打包程序的一个问题!
- 新建一个组件,继承自RichEdit组件,想加上透明度和背景图的属性。大侠给点思路。谢谢!
- delphi7的问题,indy client组件下的idftp控件能实现文件传输的问题吗?
- idftpserver的问题
- 求教,程序运行计时显示
- 动态改变dbgrid单元格颜色(某一个单元格,而不是行)
- 谁会用DELPHI编写WIN 2000中隐藏进程的程序?请帮帮我!快急死了!!!
- 注册码的问题
- delphi ado 分批查询数据
下面就是多线程的例子.你把代码放进那个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.
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.
但是执行起来还是有记时停顿的现象,我是菜鸟,请前辈能指点清楚,或给个实用的代码好么,感谢!