N
newmoonfaw
Unregistered / Unconfirmed
GUEST, unregistred user!
刚试着学多线程,想用indy做下载,但在下载过程中用户界面还是没响应,直到下载完毕才响应,不知道哪里错了。程序简单内容如下:
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdHTTP;
type
TDownloadThread=class(TThread)
private
Answer:integer;
Protected
Proceduredo
wnload;
Procedure Execute;Override;
end;
TMainForm = class(TForm)
Memo1: TMemo;
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
Label2: TLabel;
Edit2: TEdit;
Button2: TButton;
IdHTTP1: TIdHTTP;
sdlg: TSaveDialog;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.DFM}
procedure TMainForm.Button1Click(Sender: TObject);
var NewThread:TDownloadThread;
begin
NewThread:=TDownloadThread.create(False);
end;
Procedure TDownloadThread.Download ;
var tmpStream:TFileStream;
begin
with MainFormdo
begin
try
idhttp1.Get(Edit1.Text,tmpStream);
finally
tmpStream.Free;
end;
end;
end;
Procedure TDownloadThread.Execute;
begin
FreeOnTerminate:=true;
Synchronize(Download);
end;
end.
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdHTTP;
type
TDownloadThread=class(TThread)
private
Answer:integer;
Protected
Proceduredo
wnload;
Procedure Execute;Override;
end;
TMainForm = class(TForm)
Memo1: TMemo;
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
Label2: TLabel;
Edit2: TEdit;
Button2: TButton;
IdHTTP1: TIdHTTP;
sdlg: TSaveDialog;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.DFM}
procedure TMainForm.Button1Click(Sender: TObject);
var NewThread:TDownloadThread;
begin
NewThread:=TDownloadThread.create(False);
end;
Procedure TDownloadThread.Download ;
var tmpStream:TFileStream;
begin
with MainFormdo
begin
try
idhttp1.Get(Edit1.Text,tmpStream);
finally
tmpStream.Free;
end;
end;
end;
Procedure TDownloadThread.Execute;
begin
FreeOnTerminate:=true;
Synchronize(Download);
end;
end.