wenn ich folgenden Code von meinem Main-Form aus ausführe, blockiert das ganze Programm für einen Moment, selbst, nachdem ich das "sleep" rausgenommen habe. Normalerweise ist doch ein anderes Formular autoatisch ein anderer Thread, oder irre ich mich da? Könnte es helfen, diese Procedure in einem eigenen Thread auszuführen? Danke,
leosok
Code: Alles auswählen
function Tform_console.DownloadHTTP(URL:string; amemo: Tmemo): boolean;
// Download file; retry if necessary.
// Deals with SourceForge download links
// Could use Synapse HttpGetBinary, but that doesn't deal
// with result codes (i.e. it happily downloads a 404 error document)
const
MaxRetries=3;
var
HTTPGetResult: boolean;
HTTPSender: THTTPSend;
RetryAttempt: integer;
begin
result:=false;
RetryAttempt:=1;
//Optional: mangling of Sourceforge file download URLs; see below.
//URL:=SourceForgeURL(URL); //Deal with sourceforge URLs
HTTPSender:=THTTPSend.Create;
try
try
// Try to get the file
HTTPGetResult:=HTTPSender.HTTPMethod('GET', URL);
while (HTTPGetResult=false) and (RetryAttempt<MaxRetries) do
begin
// sleep(500*RetryAttempt);
// Application.ProcessMessages;
HTTPGetResult:=HTTPSender.HTTPMethod('GET', URL);
RetryAttempt:=RetryAttempt+1;
end;
// If we have an answer from the server, check if the file
// was sent to us.
case HTTPSender.Resultcode of
100..299:
begin
amemo.lines.LoadFromStream(HTTPSender.Document);
result:=true;
end;
//informational, success
300..399: result:=false; //redirection. Not implemented, but could be.
400..499: result:=false; //client error; 404 not found etc
500..599: result:=false; //internal server error
else result:=false; //unknown code
end;
except
// We don't care for the reason for this error; the download failed.
result:=false;
end;
finally
HTTPSender.Free;
end;
end;