M
messah
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit2;interfaceuses Classes,Registry;type do
wnload = class(TThread) private { Private declarations } public constructor create;
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, proceduredo
wnload.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. }{do
wnload }constructordo
wnload.create;
begin
inherited Create(True);
end;
proceduredo
wnload.Execute;var savefilestream:TFilestream;
Reg:TRegistry;
begin
tryForm1.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;exceptForm1.Close;
end;
{ Place thread code here }end;
end.
线程代码如上,在主程序中用download.create调用。可是出错。不下载文件,请教大家我哪里错了。谢谢
wnload = class(TThread) private { Private declarations } public constructor create;
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, proceduredo
wnload.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. }{do
wnload }constructordo
wnload.create;
begin
inherited Create(True);
end;
proceduredo
wnload.Execute;var savefilestream:TFilestream;
Reg:TRegistry;
begin
tryForm1.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;exceptForm1.Close;
end;
{ Place thread code here }end;
end.
线程代码如上,在主程序中用download.create调用。可是出错。不下载文件,请教大家我哪里错了。谢谢