多线程下载页面代码问题我想用线程下载页面代码,但不行,请指教:unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdHTTP, StdCtrls;type
TForm1 = class(TForm)
IdHTTP1: TIdHTTP;
Button1: TButton;
Button3: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TThread1 = class(TThread)
private
tURL,html:string;
TT:Tmemo;
protected
procedure Execute; override;
public
constructor create1(aURL:string;text:Tmemo);
procedure show;
end;var
Form1: TForm1;var
thread1:TThread1;implementation{$R *.dfm}
//构造函数
constructor TThread1.create1(aURL:string;text:Tmemo);begin
tURL := aURL;
TT:=text;
FreeOnTerminate := true;
inherited create(false);end;procedure TThread1.Execute;
var
idhttp1:tidhttp;
aURL:string;
begin
IdHTTP1:=TIdHTTP.Create(nil);
html:=Idhttp1.Get(aURL);
end;procedure TThread1.show ;
begin
TT.Lines.Add(html);
end;
//执行下载
procedure TForm1.Button1Click(Sender: TObject);
begin
thread1:=TThread1.create1('http://news.sina.com.cn/china/important/2007-03-23/index.html',memo1);
Showmessage('OK!主线程在执行');
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
thread1.Suspend ;
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdHTTP, StdCtrls;type
TForm1 = class(TForm)
IdHTTP1: TIdHTTP;
Button1: TButton;
Button3: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TThread1 = class(TThread)
private
tURL,html:string;
TT:Tmemo;
protected
procedure Execute; override;
public
constructor create1(aURL:string;text:Tmemo);
procedure show;
end;var
Form1: TForm1;var
thread1:TThread1;implementation{$R *.dfm}
//构造函数
constructor TThread1.create1(aURL:string;text:Tmemo);begin
tURL := aURL;
TT:=text;
FreeOnTerminate := true;
inherited create(false);end;procedure TThread1.Execute;
var
idhttp1:tidhttp;
aURL:string;
begin
IdHTTP1:=TIdHTTP.Create(nil);
html:=Idhttp1.Get(aURL);
end;procedure TThread1.show ;
begin
TT.Lines.Add(html);
end;
//执行下载
procedure TForm1.Button1Click(Sender: TObject);
begin
thread1:=TThread1.create1('http://news.sina.com.cn/china/important/2007-03-23/index.html',memo1);
Showmessage('OK!主线程在执行');
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
thread1.Suspend ;
end;end.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货