S
Squallleonchat
Unregistered / Unconfirmed
GUEST, unregistred user!
正如问题所示,我想在memo中用多线程显示一个网页的代码
unit Unit1;
interface
uses
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(true);
end;
procedure TThread1.Execute;
var
idhttp1:tidhttp;
aURL:string;
begin
IdHTTP1:=TIdHTTP.Create(nil);
html:=Idhttp1.Get(aURL);
end;
procedure TThread1.show ;
begin
TT.Text := 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.
unit Unit1;
interface
uses
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(true);
end;
procedure TThread1.Execute;
var
idhttp1:tidhttp;
aURL:string;
begin
IdHTTP1:=TIdHTTP.Create(nil);
html:=Idhttp1.Get(aURL);
end;
procedure TThread1.show ;
begin
TT.Text := 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.