6 Classes, IdHttp, IdException, SysUtils, Dialogs;
9 THTTPDownloadThread = class(TThread)
18 FOnSuccess: TNotifyEvent;
19 FOnConnectionFailed: TNotifyEvent;
20 procedure SetProxyPort(const Value: integer);
21 procedure SetProxyServer(const Value: String);
22 procedure SetOnConnectionFailed(const Value: TNotifyEvent);
23 procedure SetOnSuccess(const Value: TNotifyEvent);
25 procedure Execute; override;
27 procedure DoConnectionFailed;
29 constructor Create(const Host, URL, Post: String); reintroduce;
30 property RecvString: String read FRecvString;
31 property ProxyServer: String read FProxyServer write SetProxyServer;
32 property ProxyPort: integer read FProxyPort write SetProxyPort;
33 property OnConnectionFailed: TNotifyEvent read FOnConnectionFailed write SetOnConnectionFailed;
34 property OnSuccess: TNotifyEvent read FOnSuccess write SetOnSuccess;
40 \88Ù
\82È
\82é
\83X
\83\8c\83b
\83h
\82ª
\8f\8a\97L
\82·
\82é VCL
\82Ì
\83\81\83\
\83b
\83h/
\8aÖ
\90\94/
\83v
\83\8d\83p
\83e
\83B
\82ð
41 \95Ê
\82Ì
\83X
\83\8c\83b
\83h
\82Ì
\92\86\82©
\82ç
\88µ
\82¤
\8fê
\8d\87\81A
\94r
\91¼
\8f\88\97\9d\82Ì
\96â
\91è
\82ª
\94
\90¶
\82µ
\82Ü
\82·
\81B
43 \83\81\83C
\83\93\83X
\83\8c\83b
\83h
\82Ì
\8f\8a\97L
\82·
\82é
\83I
\83u
\83W
\83F
\83N
\83g
\82É
\91Î
\82µ
\82Ä
\82Í Synchronize
44 \83\81\83\
\83b
\83h
\82ð
\8eg
\82¤
\8e\96\82ª
\82Å
\82«
\82Ü
\82·
\81B
\91¼
\82Ì
\83I
\83u
\83W
\83F
\83N
\83g
\82ð
\8eQ
\8fÆ
\82·
\82é
\82½
\82ß
45 \82Ì
\83\81\83\
\83b
\83h
\82ð
\83X
\83\8c\83b
\83h
\83N
\83\89\83X
\82É
\92Ç
\89Á
\82µ
\81ASynchronize
\83\81\83\
\83b
\83h
\82Ì
46 \88ø
\90\94\82Æ
\82µ
\82Ä
\93n
\82µ
\82Ü
\82·
\81B
48 \82½
\82Æ
\82¦
\82Î
\81AUpdateCaption
\83\81\83\
\83b
\83h
\82ð
\88È
\89º
\82Ì
\82æ
\82¤
\82É
\92è
\8b`
\82µ
\81A
50 procedure THTTPDownloadThread.UpdateCaption;
52 Form1.Caption := 'THTTPDownloadThread
\83X
\83\8c\83b
\83h
\82©
\82ç
\8f\91\82«
\8a·
\82¦
\82Ü
\82µ
\82½';
55 Execute
\83\81\83\
\83b
\83h
\82Ì
\92\86\82Å Synchronize
\83\81\83\
\83b
\83h
\82É
\93n
\82·
\82±
\82Æ
\82Å
\83\81\83C
56 \83\93\83X
\83\8c\83b
\83h
\82ª
\8f\8a\97L
\82·
\82é Form1
\82Ì Caption
\83v
\83\8d\83p
\83e
\83B
\82ð
\88À
\91S
\82É
\95Ï
57 \8dX
\82Å
\82«
\82Ü
\82·
\81B
59 Synchronize(UpdateCaption);
62 { THTTPDownloadThread }
64 constructor THTTPDownloadThread.Create(const Host, URL, Post: String);
66 inherited Create(true);
72 procedure THTTPDownloadThread.DoConnectionFailed;
74 FOnConnectionFailed(self);
77 procedure THTTPDownloadThread.DoSuccess;
82 procedure THTTPDownloadThread.Execute;
84 TmpStr: TStringStream;
90 Http := TIdHTTP.Create(nil);
92 Http.ProxyParams.ProxyServer := ProxyServer;
93 Http.ProxyParams.ProxyPort := ProxyPort;
94 if FPost = '' then begin
95 FRecvString := Http.Get(FURL);
97 TmpStr := TStringStream.Create(FPost);
98 FRecvString := Http.Post(FURL, TmpStr);
100 if Assigned(FOnSuccess) then Synchronize(DoSuccess);
102 on E:EIdException do begin
103 ShowMessage(E.Message);
104 if Assigned(FOnConnectionFailed) then Synchronize(DoConnectionFailed);
109 if TmpStr <> nil then TmpStr.Free;
113 procedure THTTPDownloadThread.SetOnConnectionFailed(
114 const Value: TNotifyEvent);
116 FOnConnectionFailed := Value;
119 procedure THTTPDownloadThread.SetOnSuccess(const Value: TNotifyEvent);
124 procedure THTTPDownloadThread.SetProxyPort(const Value: integer);
126 if not Suspended then
129 raise EIdException.Create('Tried to change proxy without suspending');
132 procedure THTTPDownloadThread.SetProxyServer(const Value: String);
134 if not Suspended then
135 FProxyServer := Value
137 raise EIdException.Create('Tried to change proxy without suspending');