[英]How to turn my Delphi Class (from idHTTP) into a "Thread"?
我已經編寫了 idHTTP 的后代來為各種 Web 服務實現我自己的通信類。
即時通訊協議
|
網絡API
|
TWebOAuthAPI
|
SpotifyAPI
既然這一切似乎都如我所願,我 - 當然 - 經歷了互聯網的延遲,因此在我的應用程序中“掛起”使用所述類,因為它們等待 idHTTP 的超時。 所以這個想法是把我的班級變成一個單獨的線程,這樣至少主程序不會停頓。 我該怎么做?
我應該將 WebAPI 變成 TThread 的后代並在其中包含一個 TidHTTP 對象,還是稍后使用一個使用 TSpotifyAPI 對象的包裝器?
感謝您在這方面的任何提示:-)
如果在創建Thread
時遵循正常規則,則可以創建TThread
后代並在內部使用 TIdHttp 組件而不會出現問題。
有一段時間我做了一個類來使用包含 TidHttp 組件的線程下載圖像,沒有問題。
{: Clase para descargar una imagen y almacenarla en disco.}
{: Class to download a image and save it to disk}
TDownImageThread = class(TThread)
private
FURLImage: string;
FPathImage: string;
FFileNameImage: string;
// Internas
ImageName: string;
PathURL: string;
// Componente
idH:TidHTTP;
public
// redefinir métodos
constructor Create(AURL:string; AOutPathImages:string);
destructor Destroy; override;
procedure Execute; override;
{: URL de la imagen a descargar/ URL of the image }
property URLImage:string read FURLImage write FURLImage;
{: Path de disco local donde voy a almacenar la imagen/ Local path to save the image}
property PathImage:string read FPathImage;
{: Nombre completa (path+Nombre) de la imagen almacenada en disco local/Compete path on local}
property FileNameImage:string read FFileNameImage;
end;
發展與其他線程相同。
在這種情況下更簡單,因為它不包括視覺部分,因此您可以避免與同步相關的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.