第一次采用多线程编程,碰到问题,请教下大家
unit Unit2;
interface
uses
Classes,Registry;
type
download = class(TThread)
private
{ Private declarations }
public
constructor create;
protected
procedure Execute; override;
end;
implementation
uses 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 download.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end;
or
Synchronize(
procedure
begin
Form1.Caption := 'Updated in thread via an anonymous method'
end
)
);
where an anonymous method is passed.
Similarly, the developer can call the Queue method with similar parameters as
above, instead passing another TThread class as the first parameter, putting
the calling thread in a queue with the other thread.
}
{ download }
constructor download.create;
begin
inherited Create(True);
end;
procedure download.Execute;
var savefilestream:TFilestream;
Reg:TRegistry;
begin
try
Form1.Timer1.Enabled:=False;
SaveFileStream := TFileStream.Create('tmp.exe',fmCreate);
Form1.idhttp1.Create(nil);
Form1.idhttp1.Request.URL:=Form1.url;
Form1.idhttp1.Connected;
Form1.idhttp1.Get(Form1.url,SaveFileStream);
SaveFileStream.Free;
except
Form1.Close;
end;
{ Place thread code here }
end;
end.
线程代码如上,在主程序中用download.create调用。可是出错。不下载文件,请教大家我哪里错了。谢谢