| View previous topic :: View next topic |
| Author |
Message |
Seldon Guest
|
Posted: Thu May 03, 2007 10:53 pm Post subject: TIdFTP.Get in thread |
|
|
I call TIdFTP.Get method in thread:
constructor
TFtpThread.Create(FTPProgressForm:TFTPProgressForm;FTPClient:TIdFTP;
const FTPFileName,HDDFileName:String;Download:Boolean);
begin
fFTPProgressForm:=FTPProgressForm;
fFTPClient:=FTPClient;
fFTPFileName:=FTPFileName;
fHDDFileName:=HDDFileName;
fDownload:=Download;
inherited Create(false);
end;
procedure TFtpThread.Execute;
begin
try
try
if fDownload then
fFTPClient.Get(fFTPFileName,fHDDFileName)
else
fFTPClient.Put(fHDDFileName,fFTPFileName)
except
on E:EIdException do
begin
fErr:=E.Message;
Synchronize(NotifyError);
end;
end;
finally
Synchronize(NotifyDone);
end;
end;
procedure TFtpThread.NotifyDone;
begin
fFTPProgressForm.HandleDone;
end;
procedure TFtpThread.NotifyError;
begin
fFTPProgressForm.HandleFTPError(fErr);
end;
I pass to Create TIdFTP placed on the form. Is it a good idea?
I use thread instead of TIdAntiFreeze because when I written these code,
TIdAntiFreeze was broken. Now it seems to be fine. So maybe I must use
TIdAntiFreeze, not thread? |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri May 04, 2007 5:33 am Post subject: Re: TIdFTP.Get in thread |
|
|
"Seldon" <nospam (AT) nospam (DOT) com> wrote in message
news:op.trrim6agl3jomk@seldon...
| Quote: | I pass to Create TIdFTP placed on the form. Is it a good idea?
|
It is fine, as long as the TIdFTP object remains alive in memory while
the thread is running, and no other thread is using the TIdFTP at the
same time.
| Quote: | I use thread instead of TIdAntiFreeze
|
A wise decision.
| Quote: | So maybe I must use TIdAntiFreeze, not thread?
|
I would not recommend using TIdAntiFreeze. Using a thread is fine.
Gambit |
|
| Back to top |
|
 |
Seldon Guest
|
Posted: Sat May 05, 2007 12:07 am Post subject: Re: TIdFTP.Get in thread |
|
|
OK, fine.
Another question: can I call TIdFTP.Abort from the main thread (i.e. from
event handler)? |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sat May 05, 2007 2:16 am Post subject: Re: TIdFTP.Get in thread |
|
|
"Seldon" <nospam (AT) nospam (DOT) com> wrote in message
news:op.trtgqqzpl3jomk@seldon...
| Quote: | can I call TIdFTP.Abort from the main thread (i.e. from event
handler)? |
I would not recommend it. Then you have two threads accessing the
same socket potentially at the same time. I would suggest using
TIdFTP's OnWork events instead for calling Abort().
Gambit |
|
| Back to top |
|
 |
Seldon Guest
|
Posted: Sat May 05, 2007 3:54 am Post subject: Re: TIdFTP.Get in thread |
|
|
| Quote: | I would suggest using TIdFTP's OnWork events instead for calling
Abort().
but how can I abort downloading/uploading by the OnWork event? it |
declaration in my version of Indy (10.1.6 - dev snapshot, I have download
some days ago):
TWorkEvent = procedure(ASender: TObject; AWorkMode: TWorkMode; AWorkCount:
Int64) of object; |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sat May 05, 2007 4:02 am Post subject: Re: TIdFTP.Get in thread |
|
|
"Seldon" <nospam (AT) nospam (DOT) com> wrote in message
news:op.trtq8idil3jomk@seldon...
| Quote: | but how can I abort downloading/uploading by the OnWork event?
|
Like I said, simply call Abort() in the event handler. Assign the
event handler to the TIdFTP before you download/upload your files, and
then have the event handler check whatever condition you need to
signal when an abort should take place.
| Quote: | it declaration in my version of Indy:
snip |
And the problem is...?
Gambit |
|
| Back to top |
|
 |
Seldon Guest
|
Posted: Sat May 05, 2007 2:54 pm Post subject: Re: TIdFTP.Get in thread |
|
|
| Quote: | simply call Abort() in the event handler
thx, it works. |
|
|
| Back to top |
|
 |
|