![]() |
Re: Indy freeze Problem
hmm was ist da falsch?
Delphi-Quellcode:
und dann:
function ThreadedHTTP(URL:string):string;
var Thttp : TidHTTP; QuellCode : string; begin Thttp := TidHTTP.Create (nil); try QuellCode := Thttp.Get(URL); finally Thttp.Free; result := QuellCode; End End;
Delphi-Quellcode:
QuellCodeTechnobase := ThreadedHTTP('http://www.technobase.fm');
application.ProcessMessages; QuellCodeTrancebase := ThreadedHTTP('http://www.trancebase.fm'); application.ProcessMessages; QuellCodeHardbase := ThreadedHTTP('http://www.hardbase.fm'); application.ProcessMessages; QuellCodeHousetime := ThreadedHTTP('http://www.housetime.fm'); |
Re: Indy freeze Problem
Nix is falsch. Nur falls du denkst, dass das jetzt "threaded" ist, dann liegst du falsch :roll:
|
Re: Indy freeze Problem
Zitat:
|
Re: Indy freeze Problem
Zitat:
![]() |
Re: Indy freeze Problem
Also ich weiß nicht wo das Problem ist. Du erstellst eine Thread-Klasse von TThread abgeleitet. Dieser fügst du ein neues Property URL hinzu. In der Execute-Methode erstellst du die Indy-Komponente und gibst sie am Ende wieder frei:
Delphi-Quellcode:
Und der Aufruf:
unit Unit3;
interface uses Classes; type TDownloadThread = class(TThread) private { Private-Deklarationen } FURL: string; FCode: string; procedure ShowCode; public property URL: string read FURL write FURL; protected procedure Execute; override; end; implementation uses IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, Unit2; { TDownloadThread } procedure TDownloadThread.Execute; var IdHTTP: TIdHTTP; begin IdHTTP := TIdHTTP.Create(nil); try FCode := IdHTTP.Get(URL); finally IdHTTP.Free; end; Synchronize(ShowCode); end; procedure TDownloadThread.ShowCode; begin Form2.Memo1.Text := FCode; end; end.
Delphi-Quellcode:
Das sollte als Grundgerüst reichen. Das ganze kann man jetzt noch um eine Fortschrittsanzeige und die Möglichkeit das ganze abzubrechen erweitern.abzubrechen
uses
Unit3; procedure TForm2.Button1Click(Sender: TObject); var DownloadThread: TDownloadThread; begin DownloadThread := TDownloadThread.Create(True); DownloadThread.FreeOnTerminate := True; DownloadThread.URL := 'http://www.michael-puff.de'; DownloadThread.Resume; end; |
Re: Indy freeze Problem
Zitat:
|
Re: Indy freeze Problem
Liste der Anhänge anzeigen (Anzahl: 1)
Hast du ein Glück, dass ich nicht schlafen kann. Im Anhang eine lauffähige Demo inklusive Ereignissen. Bei mir friert da nichts ein. Einfriren tut es nur, wenn du andauernt Synchronize aufrufst, denn der Code wird dann im Kontext des Hauptthreads ausgeführt und gerade das wollen wir ja nicht. aLSO Synchronize nicht zu häufig aufrufen.
|
Re: Indy freeze Problem
Zitat:
|
Re: Indy freeze Problem
Zitat:
Zitat:
SO muss des aussehen, ja ne jetzt tuts auch danke! |
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:06 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz